-
Notifications
You must be signed in to change notification settings - Fork 1.4k
PropTypes.node forbids true but flow typing accepts it, causing runtime warning #310
Comments
Sounds like the flow types (which are maintained in a separate package) have a bug. I’d suggest filing this issue there :-) |
|
Ah, I misunderstood. You're saying that react itself changed to allow It'd be great if we could figure out in which version that changed. |
Perhaps the type has not been changed since 2014: (the first commit which contains
|
Perhaps the first step then is to file an issue on react to ask them to update the flow type. Once that's updated, and once it's clear when that change in React proper happened, it should be straightforward to update it here. |
AFAIK current state is:
So React and its flow type are already in sync for |
Did some testing; looks like prior to React 16, |
Can you please share your test method? If you were trying to return UPD: it works in React 15 without any warnings: https://codesandbox.io/s/boring-goldberg-6qgnh?fontsize=14&hidenavigation=1&theme=dark |
(similar to #109) @Hypnosphi i just loaded up a bunch of react versions in a code sandbox and verified which ones gave a runtime warning or not. I was using true as a child of a div. In other words, what i said was “prior to react 16, it was disallowed” which does not conflict with “works in 15”. |
Sorry, but how is 15 not prior to 16? |
So which versions gave warnings? |
“disallowed < 16” means “does not work on 15”, I’m not sure where the confusion is. Every version 15 and below gave warnings. |
Can you please share a link to codesandbox? I have posted one above, and it gives no warnings
It doesn't make sense to me, sorry. Did you mean "does conflict" or something? |
I discarded the link, so i have no link to share. No, i meant does NOT conflict. React 16 worked, react 15 didn’t, with true as a child. I see that you are claiming that react 15 works, but your own sandbox has an invariant warning in the console, so react 15 seems to not work. |
Oh, looks like I had to fork the shared sandbox before playing with it, my bad. I reverted the changes, please check again https://codesandbox.io/s/boring-goldberg-6qgnh UPD: also, React 0.14: https://codesandbox.io/s/relaxed-fermi-7kgc4 |
Fair, those seem to work. Can you provide a react 0.13 sandbox with a class component to verify if that one fails? |
Nope 0.13 with class: https://codesandbox.io/s/sad-haze-yykbq |
Then I’m very confused. If true has always been allowed, then i don’t know why the node propType ever disallowed it. I’m still happy to loosen it to accept true, but before i do id like to understand the disparity. |
PropTypes.node does not accept true according to #109.
But flow typing in React declares
export type ReactEmpty = null | void | boolean;
https://github.com/facebook/react/blob/b6173e643a4311b9b1cf039824b2f3d7b974b8cf/packages/shared/ReactTypes.js#L18 so it accepts
true
without error for type checking, but prop-types shows warning for it.(Actually I'm using equivalent TypeScript type definition along with material-ui library which uses prop-types.)
The text was updated successfully, but these errors were encountered: