Flow: unresolved type $ReadOnlyArray

I'm trying to get the IDE to recognize Flow native types, but with no success.

I have ESLint installed on my project. Not sure why Flow isn't able to parse them.

All my node modules are latest.

Here's a portion of what my .eslintrc.json looks like:

{
"env": {
"es6": true,
"node": true
},
"extends": ["eslint:recommended"],
"globals": {
"$ReadOnlyArray": true,
},
"parser": "babel-eslint",
"plugins": [
"babel",
"flowtype"
]
}
10 comments
Comment actions Permalink

What error do you see namely? Please provide code snippet and a screenshot of the error message

1
Comment actions Permalink

The error message is simply `unresolved type $ReadOnlyArray`

It's as though flow/eslint is unable to recognise this type.

 

as for a code snippet, you can simply do this:

type Abc = $ReadOnlyArray<any> // Shows the error.

type Def = Array<any>  // Works fine.

2
Comment actions Permalink

Webstorm doesn't use .eslintrc for types resolving, so adding types to ESlint globals won't help. Neither it supports Flow libdefs  - see https://youtrack.jetbrains.com/issue/WEB-27437

0
Comment actions Permalink

That's strange because another project of mine works fine and I have no idea why. It uses the same .eslintrc, slightly earlier versions of relevant node modules.

I.e. the IDE recognises the type $ReadOnlyArray and provides proper code-completion.

Also libraries on github (i.e. those which use flow and utilize newer flow types like $ReadOnlyArray) work properly when opened in the IDE.

0
Comment actions Permalink

it must be resolving this definition from certain file you have in your project... You can Ctrl+click on it to see what definition is being used

0
Comment actions Permalink

Ahh...

I notice that the problem goes away when I switch the IDE to use Flow globally rather than from the Project modules.

My version of Flow installed globally is 0.59, while the project Flow module is 0.61. These utility types existed since 0.34...

0
Comment actions Permalink

Is there a reason why both flow packages would yield differently?

0
Comment actions Permalink

I'm not aware of any...

0
Comment actions Permalink

Any resolution here? I'm getting a similar error with flow-bin version 0.69 when I use utility types like $Keys. I get a Webstorm error "Unresolved type $Keys".

My Preferences > Languages & Frameworks > Javascript > Javascript language version is set to "Flow".

I'm using Webstorm 2018.2.3 build #WS-182.4323.44

0
Comment actions Permalink

No resolution so far... please follow https://youtrack.jetbrains.com/issue/WEB-32425 and linked tickets for updates

 

To resolve the issue, you can try adding Flow core library global type definitions to your project javaScript libraries, as it's suggested in https://youtrack.jetbrains.com/issue/WEB-32396

0

Please sign in to leave a comment.