Skip to content

[PropTypes] Add warnings if PropTypes return functions#3383

Merged
sophiebits merged 2 commits intofacebook:masterfrom
ariabuckles:proptype-warnings
Mar 11, 2015
Merged

[PropTypes] Add warnings if PropTypes return functions#3383
sophiebits merged 2 commits intofacebook:masterfrom
ariabuckles:proptype-warnings

Conversation

@ariabuckles
Copy link
Copy Markdown
Contributor

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

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`
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: call the prop something other than prop so we can distinguish these two arguments?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea :)

@sophiebits
Copy link
Copy Markdown
Collaborator

lgtm otherwise, thank you!

@ariabuckles
Copy link
Copy Markdown
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
@sophiebits sophiebits merged commit d9e0646 into facebook:master Mar 11, 2015
@sophiebits
Copy link
Copy Markdown
Collaborator

Thank you!

@ariabuckles
Copy link
Copy Markdown
Contributor Author

yay thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants