-
Notifications
You must be signed in to change notification settings - Fork 24.7k
Resolve react flow definitions #5489
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
Conversation
By analyzing the blame information on this pull request, we identified @gabelevi, @janicduplessis and @nicklockwood to be potential reviewers. |
Looks reasonable. |
@facebook-github-bot shipit |
Thanks for importing. If you are an FB employee go to https://our.intern.facebook.com/intern/opensource/github/pull_request/1643491035911286/int_phab to review. |
Shouldn't both names work? https://github.com/facebook/flow/blob/2fdb38c9f31a4a361f3823ef5e901490017810a8/lib/react.js#L181-L185 |
@spicyj hmm that does look like it should work, but I've tested with fresh RN projects on flow 20.1, and for some reason this class of error is only caught with this change. I haven't done any deeper investigation to see if the react flow interface was loading in RN at all. Since moving from React -> react is on FB's roadmap anyway I figured this was the easiest solution. |
@corbt updated the pull request. |
1 similar comment
@corbt updated the pull request. |
This is still necessary with flow 0.21 @facebook-github-bot shipit |
Thanks for importing. If you are an FB employee go to https://our.intern.facebook.com/intern/opensource/github/pull_request/1643491035911286/int_phab to review. |
Failed with a Flow error that looks unrelated. @facebook-github-bot shipit |
Thanks for importing. If you are an FB employee go to https://our.intern.facebook.com/intern/opensource/github/pull_request/1643491035911286/int_phab to review. |
I see lots of Flow errors blocking this, e.g.:
Looks like Travis shows similar errors? https://travis-ci.org/facebook/react-native/jobs/107038581 |
Removing 'Import failed' because the Flow errors might be legit. |
@corbt What is |
@mkonicek Flow does look at propTypes. Flow type definitions have three main advantages over propTypes in my experience: 1) they're analyzed statically, so you don't have to wait until the code is run to detect issues, 2) they can express more sophisticated types than propTypes (permitting cool stuff like exhastiveness checks in switch statements), and 3) you can use the same type system anywhere in your program, not just at the boundary between components. Also apparently React is moving towards encouraging Flow over propTypes anyway (facebook/react#1833 (comment)). The three parameters to Component above are the types of props, state and defaultProps. It's true that this change generates a ton of Flow errors internally (I count 207), but that's because those components actually do have Flow errors (mostly related to not declaring the type of If this PR needs to fix all the internal Flow errors as well I can probably do that, but it's going to be a giant PR. ;) |
Can propTypes be analyzed statically? Don't have enough context to comment on 2 and 3. From facebook/react#1833 (comment):
I'll cc @zpao from React and @jeffmo from Flow here because I don't have much context to review this PR. Does moving from PropTypes to Flow mean you'd declare your components as
I see, that's sad. I think we'd need to update all of those first before landing this unless @jeffmo knows a better way? |
I'm happy to fix the flow errors generated by this change if that sounds good to you. It'll probably be a fairly large diff but it's a pretty mechanical process (mostly adding missing definitions) and things will be better typechecked afterwards. |
@mkonicek yeah all this PR does is fix Flow's checks, propTypes will continue working as-is (and are detected by flow). The changes I'd have to make would also leave all current propTypes in place, just add definitions to components that are missing propTypes and types on other properties. |
@corbt updated the pull request. |
(btw, the github bot has claimed I've updated this and several other PRs recently that I haven't changed, not sure what's going on with that) |
@corbt updated the pull request. |
zpao tells me he has the same comment as spicyj. |
Is the motivation for this PR to support declaring the props as e.g.:
Is it likely people will want to use that syntax? |
No, the motivation for this PR is to fix React Native to use the correct I also agree with @spicyj and @zpao that this should already be working Alternatively, note all the new flow errors created by this PR. If you've On Mon, Feb 22, 2016, 12:25 AM Martin Konicek [email protected]
|
Your PR clearly shows that 'React' and 'react' are different things for Flow.
With this PR we get a lot of Flow errors. How would a sample fix of one of them like and what fixing it give us? Sorry for all the back and forth. I don't have enough context yet and the people with the right context haven't been responsive on this PR. This might be really hard to land with so many Flow errors in open source that have to be fixed and probably many more in internal closed source apps. |
@corbt updated the pull request. |
Ok, I've added another commit to this PR that actually fixes all of the broken flow definitions. It does so mainly by setting the types of undeclared state and/or props to I also created a separate commit corbt@faf7cfa that manages to "really" fix flow errors by setting the proper types for I recommend merging this PR now that all Flow errors are fixed, and then going in and adding the real definitions instead of just PS enjoy the conference! I'll be watching on the youtube stream, and will understand if it takes a few days to get back on this PR. ;) |
@corbt Awesome work. We really need to fix all the Flow errors. Right now it's not usable with Flow at all. I had to add RN to the ignore list in my project :( LGTM. Need to fix the conflicts though. |
@corbt updated the pull request. |
Conflicts fixed. |
@facebook-github-bot shipit |
Thanks for importing. If you are an FB employee go to Phabricator to review. |
Actually Flow 0.22 is a lot better at detecting these errors. Never got previous versions of Flow to work with propTypes. |
Summary:Currently, we're not taking advantage of Flow's built-in type definitions for the React library in all cases because Flow's definition uses `declare module react` and this file uses `import('React')`, which Flow thinks is a different library. After this change, the following starts working which didn't before: ```js import { Component } from 'react-native'; class MyText extends Component<void, {text: string}, void> { render() { return <Text>{this.props.text}</Text> } } // Correctly throws a Flow error for the missing "text" prop const renderedText = <MyText />; ``` Closes facebook#5489 Differential Revision: D2856176 fb-gh-sync-id: 473ca188ad7d990c3e765526c4b33caf49ad9ffd shipit-source-id: 473ca188ad7d990c3e765526c4b33caf49ad9ffd
Currently, we're not taking advantage of Flow's built-in type definitions for the React library in all cases because Flow's definition uses
declare module react
and this file usesimport('React')
, which Flow thinks is a different library. After this change, the following starts working which didn't before: