-
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 validation for arrayOf and objectOf in ReactPropTypes #5390
Conversation
a180f60
to
7ae6791
Compare
@@ -144,6 +144,11 @@ function createAnyTypeChecker() { | |||
|
|||
function createArrayOfTypeChecker(typeChecker) { | |||
function validate(props, propName, componentName, location, propFullName) { | |||
if (typeof typeChecker !== 'function') { | |||
return new Error( | |||
`Invalid argument \`${propFullName}\` supplied to \`${componentName}\`, expected valid PropType.` |
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.
This message isn't awesome. You're actually trying to say that the component author wrote a bad propType spec, but the way this error will show sounds like the user provided an invalid prop value. Can we tune it so that's more clear?
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.
Is it more clear now?
Thanks for doing this, I think it's a great idea. I sort of wish I had pushed for making #3963 actually throw an error (since it would throw at require time, not component creation time). We have less contextual information we can provide but the error would actually be thrown earlier, preventing bad proptype definitions from getting committed… maybe we can do that in another pass. |
02d14b3
to
a86d25d
Compare
@chicoxyzzy updated the pull request. |
Alright, let's do it. Now that I'm thinking about proptypes again, I might have some followup ideas to try but this puts us in a better spot. |
Add validation for arrayOf and objectOf in ReactPropTypes
hey @zpao I also got a case where I had this error. I'm not exactly sure where it came from nor where I fixed it but a better error message would have helped :) Actually we register all of our Api payloads as proptypes. I think at some point the declaration order of proptypes lead to something like Maybe it's something else because I can't get this "typeChecker" error back. |
@slorber feel free to ping me if you'll meet your issue again |
Notice data property. it should look like
instead.
This is one of common mistakes. But error message is very cryptic:
Warning: Failed propType: typeChecker is not a function Check the render method of 'ChartPanel'.
So I wrote some tests and pretty error messages.
now error looks like this
Warning: Failed propType: Invalid prop 'data' supplied to 'ChartContainer', expected valid PropType. Check the render method of 'ChartPanel'.
This is kind of same as #3963 but for arrayOf and objectOf proptypes