-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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
Returning an error if a PropType is passed to ReactPropTypes.oneOf. #7526
Conversation
values[i] = 'Unexpected function: ' + values[i].toString(); | ||
} | ||
} | ||
return values; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe something like this instead?
return values.map(value => (
getPropType(value) === 'function' ? `Unexpected function: ${value}` : value
));
You shouldn't have to specially call toString
on value
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, @donavon. Thanks a lot, I implemented your recommended change :-).
Dear @aweary and @gaearon, I just noticed there was some activity about this PR [1]. So I decided to fix the merging issues. Can you kindly review? [1] #8274 (comment) |
Sorry about this! We've been busy with a React rewrite this year, and haven't really paid attention to PRs. :-( This code has moved to https://github.com/facebook/prop-types so you can make a PR there and we could review. |
I took where @philipshurpik left off with #6940 to fix #1919, as that PR can't be merged anymore and is more than a month old.
@philipshurpik, if you meant to keep on working on #6940, please let me know and I'll close this one.
The idea is to return a
PropTypeError
whenever one ofReactPropTypes
is passed toReactPropTypes.oneOf
. The error message, hints that the user might be meaning to useReactPropTypes.oneOfType
instead.createChainableTypeChecker
is called with anexpectedType
we add theexpectedType
flag to thecheckType
function (see [1])createEnumTypeChecker.validate
, ifexpectedValues[i]
is of typefunction
and it has theexpectedType
flag, we know that aReactPropTypes
has been passed, so we throw the error described abovefunction
is passed toReactPropTypes.oneOf
we improve the previous output to display "Unexpected function" and the function converted to stringAs a side note, I noticed that if
getPropType
is called withundefined
, we get the following exception:Cannot read property '@@toStringTag' of undefined
Is this expected?
[1] https://github.com/facebook/react/pull/6940/files#r68511156