[PropTypes] Add warnings if PropTypes return functions#3383
Merged
sophiebits merged 2 commits intofacebook:masterfrom Mar 11, 2015
Merged
[PropTypes] Add warnings if PropTypes return functions#3383sophiebits merged 2 commits intofacebook:masterfrom
sophiebits merged 2 commits intofacebook:masterfrom
Conversation
Summary: Right now, if a component specifies a propType as, for example, `myProp: React.PropTypes.shape`, without an actual shape parameter, any prop type will be accepted, because `React.PropTypes.shape` returns a function (the actual validator), not an Error, currently indicating that propType checking passed. This can create an unfortunate situation where a component looks like it has fully specified `propTypes`, but in fact does not. This commit addresses this by warning if a propType checker returns anything non-falsy that is not an Error (currently all the library PropTypes return null or an Error). Test Plan: Added a unit test; ran `jest` in the root repo directory. Also ran `grunt lint` and `grunt test`
Collaborator
There was a problem hiding this comment.
nit: call the prop something other than prop so we can distinguish these two arguments?
Collaborator
|
lgtm otherwise, thank you! |
Contributor
Author
|
I'll make those changes; thanks! |
Addresses comments on facebook#3383, making the invalid proptype specification warning clearer and making the tests for it a bit clearer.
sophiebits
added a commit
that referenced
this pull request
Mar 11, 2015
[PropTypes] Add warnings if PropTypes return functions
Collaborator
|
Thank you! |
Contributor
Author
|
yay thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Right now, if a component specifies a propType as, for example,
myProp: React.PropTypes.shape, without an actual shape parameter, any prop type will be accepted, becauseReact.PropTypes.shapereturns a function (the actual validator), not an Error, currently indicating that propType checking passed.This can create an unfortunate situation where a component looks like it has fully specified
propTypes, but in fact does not.This commit addresses this by warning if a propType checker returns anything non-falsy that is not an Error (currently all the library PropTypes return null or an Error).
Test Plan:
Added a unit test; ran
jestin the root repo directory.Also ran
grunt lintandgrunt test