Importing named exports from React does not work on Flow-type

626 views Asked by At

Versions

"react": "16.9.0",
"react-native": "0.61.5",
"flow-bin": "0.107.0"

The Problem

I'm working on an on-going project, the team-lead and I agreed to enforce adding static typing using Flow because it is already setup, but they are not using it.

Whenever I import named exports from React it is complaining that there is no exported module with that name. (See the attached image).

I even tried creating a new RN project with the same version as the actual project but it still showing the same errors.

enter image description here

1

There are 1 answers

1
Dennis Vash On

In flow there is no such type React.FC as it is Typescript type.

See all Type References in related docs.

// TS
const Foo: React.FC<Props> = (props) => { ... }

// Flow
const Foo = (props: Props): React.Node => { ... }

Your code is referring to a typescript type in javascript file with flow client, don't be confused.

React.FC type comes from @types/react/index.d.ts as mentioned.

type FC<P = {}> = FunctionComponent<P>;