Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing React.forwardRef definition #6103

Closed
billyjanitsch opened this issue Apr 5, 2018 · 7 comments
Closed

Missing React.forwardRef definition #6103

billyjanitsch opened this issue Apr 5, 2018 · 7 comments

Comments

@billyjanitsch
Copy link

React 16.3 introduced a new forwardRef() API, for which Flow does not currently have a definition.

@motiz88
Copy link
Contributor

motiz88 commented Jun 22, 2018

I might try to work on this over the weekend.

Looks like for maximum correctness we need a new opaque type React$RefForwardingComponent<Props> (name?) and to add it as an option to the unions React$ComponentType<Props> and React$ElementType. However, and I'm extrapolating from limited experimentation here, it looks like Flow will not typecheck these props (when used in JSX etc) unless we add special handling for RefForwardingComponent (in react_kit.ml probably?)

And then there's the option of fudging it and pretending forwardRef<Props>() returns React$ComponentType<Props>, but that's obviously unsound 🤷‍♂️

@motiz88
Copy link
Contributor

motiz88 commented Jun 23, 2018

OK, having done some digging, I'm going to make a PR with the less-correct solution, typing forwardRef as returning ComponentType<Props>. I'm basing this on the existing libdef for createContext: It models Provider and Consumer as ComponentType<Props> even though internally they're plain objects distinguished by their $$typeof property, and therefore are neither callable nor are they classes extending React.Component.

Ideally we would model these React builtins using a first-class "opaque component" type so we could catch certain errors that the current model will happily allow (and consider to have full type coverage).

@tiarebalbi
Copy link

Any idea of which release this will be part of? Thanks

@jbrown215
Copy link
Contributor

@tiarebalbi 0.89

@jbrown215
Copy link
Contributor

I will follow up with a blog post on how to use the new AbstractComponent type. It will coincide with the 0.89 release.

@shahzaibkhalid
Copy link

@jbrown215 Can we get any idea of timelines for release?

@jbrown215
Copy link
Contributor

At the latest, December 19th, but hopefully December 12th. Call these dates tentative, since unexpected blockers might pop up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants