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

Warn when multiple arguments were supplied to oneOf #244

Merged
merged 1 commit into from Feb 10, 2019

Conversation

Projects
None yet
3 participants
@wojtekmaj
Copy link
Contributor

wojtekmaj commented Dec 18, 2018

Adds a different warning message for multiple arguments supplied to oneOf. A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z]) and this should help developers identifying the error.

`oneOf`: improve warning when multiple arguments are supplied
Adds a different warning message for multiple arguments supplied to oneOf. A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z]) and this should help developers identifying the error.

@wojtekmaj wojtekmaj force-pushed the wojtekmaj:feature/warn-for-multiple-oneOf-arguments branch from 53006f8 to 87964fc Dec 18, 2018

@@ -825,6 +825,20 @@ describe('PropTypesDevelopmentReact15', () => {
typeCheckPass(PropTypes.oneOf('red', 'blue'), 'red');
});

it('should warn but not error for invalid multiple arguments', () => {

This comment has been minimized.

@ljharb

ljharb Dec 18, 2018

Collaborator

Why is it better to warn here, and not throw an error? Wouldn’t that surface it most rapidly?

This comment has been minimized.

@wojtekmaj

wojtekmaj Dec 18, 2018

Author Contributor

I totally agree - it's my first contribution to prop-types so I'm being cautious here. I didn't want the output of neither oneOf('red') nor oneOf('red', 'blue') to change, as this may be considered breaking by some. So I just "enhanced" an error message in one of the cases.

Show resolved Hide resolved __tests__/PropTypesDevelopmentReact15.js Outdated
Show resolved Hide resolved __tests__/PropTypesDevelopmentStandalone-test.js Outdated
Show resolved Hide resolved factoryWithTypeCheckers.js Outdated
Show resolved Hide resolved factoryWithTypeCheckers.js Outdated
Show resolved Hide resolved factoryWithTypeCheckers.js Outdated

@wojtekmaj wojtekmaj force-pushed the wojtekmaj:feature/warn-for-multiple-oneOf-arguments branch from bbd699a to bed2bd7 Feb 10, 2019

@ljharb

ljharb approved these changes Feb 10, 2019

Copy link
Collaborator

ljharb left a comment

Thanks!

@wojtekmaj wojtekmaj force-pushed the wojtekmaj:feature/warn-for-multiple-oneOf-arguments branch from bed2bd7 to 0081280 Feb 10, 2019

@wojtekmaj

This comment has been minimized.

Copy link
Contributor Author

wojtekmaj commented Feb 10, 2019

Thanks for reviewing @ljharb. Force pushed to squash and change the unit tests to remove "instance of" from the strings you've changed.

@ljharb ljharb force-pushed the wojtekmaj:feature/warn-for-multiple-oneOf-arguments branch from 0081280 to b4c8170 Feb 10, 2019

@ljharb ljharb merged commit b4c8170 into facebook:master Feb 10, 2019

@wojtekmaj wojtekmaj deleted the wojtekmaj:feature/warn-for-multiple-oneOf-arguments branch Feb 10, 2019

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