Skip to content
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

oneOfType() does not seem to allow all types specified #388

Open
liamness opened this issue Oct 20, 2022 · 2 comments
Open

oneOfType() does not seem to allow all types specified #388

liamness opened this issue Oct 20, 2022 · 2 comments

Comments

@liamness
Copy link

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].

@ljharb
Copy link
Collaborator

ljharb commented Oct 20, 2022

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.

@liamness
Copy link
Author

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

@ljharb ljharb added the bug label Oct 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants