-
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
Support es6 symbols in proptype #4917
Comments
Here's what I use (not sure if it's the right approach): function symbol(props, propName, componentName) {
const prop = props[propName];
if (prop && (typeof prop !== 'symbol')) {
return new Error(`[${componentName}]: Expected property ${propName} to be a Symbol, but its actual type is ${typeof prop}.`);
}
}
symbol.isRequired = function(props, propName, componentName) {
return props[propName] ?
symbol(props, propName, componentName) :
new Error(`[${componentName}]: Property ${propName} is required.`);
};
export default symbol |
We've generally said no to a lot of custom proptypes checks but this one feels like it's probably ok. In theory it's a 1 line change. However we aren't applying the Symbol transform (which changes all Thoughts @sebmarkbage @spicyj |
Yea. Seems reasonable. The .constructor === Symbol as a fallback is ok. Not ideal since it doesn't work cross-realm but we should use whatever is standard practice among popular polyfills. |
Any possibility that this will be added in future versions? |
Yes, we just never got back to it. If you're interested in working on it, this is something that would make a nice addition in 15.1. |
@zpao No one is assigned? I could do a PR for it! |
Also, you can't assign issues to people who don't have commit access, making it much harder to communicate that somebody outside the core team is working on it. |
That's a shame, it seems related to isaacs/github#369 and isaacs/github#100 :/ |
Any update on this? I suppose I'll switch to string constants in this one instance, but symbols would've been better! |
We’re still ironing out how we’ll move on with cutting branches on 15.x but once it’s decided I expect this to get in. |
Looks like #6377 was merged. Should be in 15.1 or 15.2. |
Would you be open to support es6 symbols in proptype?
At the moment I'm testing them as
typeof Symbol() === 'symbol'
in custom proptype functions.The text was updated successfully, but these errors were encountered: