-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Add PropTypes for map
, set
, weakMap
, weakSet
, setOf
#6780
Add PropTypes for map
, set
, weakMap
, weakSet
, setOf
#6780
Conversation
Hmm all tests pass locally on node 6. I'll check this on node 4 |
Why not just use, PropTypes.instanceOf(Set)
PropTypes.instanceOf(WeakSet)
PropTypes.instanceOf(Map)
PropTypes.instanceOf(WeakMap) |
@satya164 why don't you ask why not just also use
? I think this should be a separate question |
Because this PR doesn't implement array. That aside, I think the general preference is to switch to Flow for type-checking and not add more stuff to |
It looks like Map, Set, WeakMap and WeakSet doesn't use |
@satya164 sure using Flow is a much better approach (personally I prefer TypeScript tho). Stuff added to PropTypes works only for dev mode so it doesn't add any overhead in production mode.
It is already implemented in React but looks like you are ok with it. Do you think that arrays are in some way "better" than other objects? |
Same can be said for Flow too.
It's used much more widely than |
For sake of consistency all types should be added to PropTypes until and if PropTypes will be deprecated That's my point |
Also I don't agree with
It depends on particular project |
anyway IMO you should create another issue if you think that some JS types should or shouldn't be in PropTypes and their presence should depend on some use frequency (and there definitely should be some statistics) |
Hmm. I agree with #6780 (comment) that PropTypes.instanceOf(Set)
PropTypes.instanceOf(WeakSet)
PropTypes.instanceOf(Map)
PropTypes.instanceOf(WeakMap) should work fine for this scenario. For arrays, I think the main reason we have This convenience feature already exists. However at some point we stopped adding convenience features to PropTypes to stop expanding their API surface, as we want to slowly transition to using Flow instead. The reason we added Unlike Symbols, |
I hope TS will be an option because a lot of people prefer TS over Flow
This is the best solution IMO. Bad thing it needs some different tweaks for different build tools. |
@gaearon is correct. Proptypes are mostly legacy and in maintenance mode right now. We don't want to increase the surface area of proptypes at the moment, if we can avoid it. @chicoxyzzy These additional proptypes would be a good thing to publish as a separate third-party library on github, if you'd like to do that :). |
I think that's not fair that only Symbol was added as PropType from ES2015 spec.
So here are
PropTypes.set
PropTypes.weakSet
PropTypes.map
PropTypes.weakMap
PropTypes.setOf