Handle private React types
gomesalexandre opened this issue · 2 comments
q.v
Line 105 in 32cb7cd
We could build a mapping, like this
React$Node: 'ReactNode',
React$Element: 'ComponentType<any>',
React$ComponentType: 'ComponentType<any>',
And then construct a matching node e.g for React$Node
, the node would convert to React.ReactNode
code.
We would of course have to check if React is imported in the current file, if not, import it using ESM syntax.
Obviously, any
is just for the example and we should handle the generics of each type, for instance, React$Element
accepts ElementType
as a generic:
https://github.com/facebook/flow/blob/master/lib/react.js#L178
The full list of private react types is available in the aforementionned file.
Thanks for filing a ticket for this.
@gomesalexandre is mapping React$Element
to ComponentType<any>
correct? Does TypeScript's React library definitions treat elements and components as the same thing?