React: PropTypes.oneOf warning does not include expected types

Created on 24 Jul 2014  Â·  10Comments  Â·  Source: facebook/react

PropType warnings for oneOf say null instead of the actual expected type.

For example, for this PropType:

  name: React.PropTypes.oneOf([
      React.PropTypes.number,
      React.PropTypes.component
   ])

I get the following warning:

Warning: Invalid prop `name` of value `World` supplied to `Hello`, expected
one of [null,null].

Example: http://jsfiddle.net/jxg/N76tr/

React v.0.11.0

starter

Most helpful comment

You wanted oneOfType. :) We can probably make the message better though…

All 10 comments

You wanted oneOfType. :) We can probably make the message better though…

:+1:

Perhaps createEnumTypeChecker needs to give a warning suggesting using oneOfType if it finds any non-strings in expectedValues?

Fixing this warning message. We're drifting away from proptypes and toward flow anyway, but if someone is looking for an easy PR, improving this error message would be a good one.

Might take a look at this. Thoughts:

We probably only want to show a suggestion if check fails and all expectedValues are functions, right? Is that an alright condition for showing the message?

Would it be valuable to also attempt something like checking if each of expectedValues name property === "bound checkType" (which looks like what the unminified PropTypes functions are)?

Hi there !!, I would like to work on this bug. @spicyj @jgebhardt can anyone point me in right direction for working on this bug?

@spicyj Hi. Is this bug still need to get fixed? I can work on it then. I want to contribute to the development of React project anyway possible.

I just made the same silly mistake and was confused by the error message. Spicyj's comment pointed me to the solution though!

PropTypes have been removed from React core and now exist as a separate package prop-types. Any future feature requests, bug reports, or changes should be directed to the new repo at https://github.com/reactjs/prop-types.

I've opened a new issue over at https://github.com/reactjs/prop-types/issues/9 for anyone looking to continue the discussion.

Was this page helpful?
0 / 5 - 0 ratings