-
Notifications
You must be signed in to change notification settings - Fork 356
Warn when multiple arguments were supplied to oneOf #244
Warn when multiple arguments were supplied to oneOf #244
Conversation
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.
@@ -825,6 +825,20 @@ describe('PropTypesDevelopmentReact15', () => { | |||
typeCheckPass(PropTypes.oneOf('red', 'blue'), 'red'); | |||
}); | |||
|
|||
it('should warn but not error for invalid multiple arguments', () => { |
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.
Why is it better to warn here, and not throw an error? Wouldn’t that surface it most rapidly?
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.
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.
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.
Thanks!
Thanks for reviewing @ljharb. Force pushed to squash and change the unit tests to remove "instance of" from the strings you've changed. |
Adds a different warning message for multiple arguments supplied to oneOf. A common mistake is to write
oneOf(x, y, z)
instead ofoneOf([x, y, z])
and this should help developers identifying the error.