Skip to content

Flow types erased for fetch #22590

@jeremywiebe

Description

@jeremywiebe

Environment

Run react-native info in your terminal and paste its contents here.
[skip envinfo]

Description

I spent some time trying to improve the flow typing in our codebase last week. I was stumped why functions using fetch couldn't properly type the return value Promise<Response>. Flow definitely includes proper typing.

I traced it down to the react-native-interface.js which erases types for fetch and it's associated types (https://github.com/facebook/react-native/blob/master/Libraries/react-native/react-native-interface.js#L21).

It looks like this was set up 4 years ago according to git blame and I suspect that was before Flow added those types as built-ins.

Reproducible Demo

In any React Native project that uses Flow, just run yarn flow type-at-pos <file-that-uses-fetch.js> row col (for a position where fetch is used).

You'll see the result is any.

If you comment out the line in the project .flowconfig that includes react-native-interface.js ([libs] section) that same flow type-at-pos command returns the correct type (Promise<Response>).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions