prop-types icon indicating copy to clipboard operation
prop-types copied to clipboard

`oneOfType()` does not seem to allow all types specified

Open liamness opened this issue 2 years ago • 2 comments

I am running into an issue where oneOfType() is passed in types of shape and string but is only allowing string seemingly.

Reproduced here (using a simplified version of types I have encountered on a project I am working on), https://jsfiddle.net/liamness/1du5jvwt/, with the warning:

Failed prop type: Invalid prop `schema[1]` supplied to `ComponentName`, expected one of type [string].

liamness avatar Oct 20 '22 10:10 liamness

The real issue is being masked here; it's that name: PropTypes.string.required, is invalid. It's .isRequired, not .required.

When I fix that, I correctly see no error.

I see the proper error message when I use just the shape - iow, oneOfType seems to be suppressing the actually helpful error message from shape, so that seems like a bug worth fixing.

ljharb avatar Oct 20 '22 18:10 ljharb

You're right, that fixes the issue. I imagine what's happening is that incorrect arguments to oneOfType are being disregarded. Thanks!

liamness avatar Oct 20 '22 20:10 liamness