-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
React.Component defaultProps
not validated by flow
#3499
Comments
|
@nmn Which Also, you could make the case that a polymorphic class like this should infer that the type is |
@mwalkerwells $Diff is used to create the prop requirements for a React Component. This way props that exist as defaultProps don't need to passed at the call-site. Also, the types here are not inferred they are defined for That said I'm investigating a possible fix that would validate that props and defaultProps are compatible.
This may or may not work. |
Can you link to this in the React.Component library definition? |
@mwalkerwells It's kind of in the Flow internals. But this gets close: https://github.com/facebook/flow/blob/master/lib/react.js#L97 |
There were a number of issues with the relationship of props and default props that have been fixed in Flow v0.53. I slightly updated the original code and it now type-checks fine in Flow v0.53. As a result, I think this can now be closed. (/cc @calebmer) |
One thing worth noting is that we only check import * as React from 'react';
class MyComponent extends React.Component<{prop: number}> {
static defaultProps = {
prop: 'foo',
};
} However, you get an error when you add |
@calebmer I'm confused about "mirrors React's runtime behavior" being a good thing. Seems like it should be possible to check this type of thing without instantiating a component? This come up a lot if you have React component packages. |
Using flow 0.41.0, with the following code:
I expected flow to alert me that
someValue
is defined as aNumber
when it should bestring
. But it does not warn me at all.The text was updated successfully, but these errors were encountered: