Flow version: 0.132.0 and above
Now flow error
Flow emits an error when I use a React type that has been imported in a flow-typed module.
Github repo: https://github.com/debel27/flow-issue_value-as-type
To reproduce : clone the project, run yarn, then run yarn run flow
The emitted error is the following
Error โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ src/index.js:4:13
Cannot use Node as a type because it is an any-typed value. Type Node properly, so it is no longer any-typed, to use it
as an annotation. [value-as-type]
1โ // @flow
2โ import * as React from 'react';
3โ
4โ const node: React.Node = <div>Hello world</div>;
5โ
One way to get around this - use the internal names. So rather than React.Element, use React$Element. A find/replace from React. to React$ in any libdef file should take care of it.
Something's really funky here, it's because of the flow-typed/types.js file you have with a import type { Node } from 'react'; inside.
flow-typed folder is handled as a "normal" file since it's not in the [libs] section of the config.import type { Node } from 'react'; should be fine, either in a lib or "normal" file.Note: react types are still part of Flow core, it's only react-dom that got moved to flow-typed for now.
In library definitions, the imports must be inside a declaration block.
declare module 'something' {
import type { Node } from 'react'
}
Regarding 1., I'm expecting flow-typed to be considered as a lib folder by default (as stated in the docs).
I was unaware there were plans of moving out React types from Flow core. Thanks for the info.
TIL: "By default, the flow-typed folder in your project root directory is included as a library directory. "
Import statements are no longer allowed at the toplevel of library files. To use import statements in library files they must appear within a "declare module".
https://github.com/facebook/flow/blob/master/Changelog.md#01430