react icon indicating copy to clipboard operation
react copied to clipboard

PropTypes.oneOf warning does not include expected types

Open jgebhardt opened this issue 12 years ago • 10 comments

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

jgebhardt avatar Jul 24 '14 06:07 jgebhardt

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

sophiebits avatar Jul 24 '14 06:07 sophiebits

:+1:

jgebhardt avatar Jul 24 '14 06:07 jgebhardt

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

mdarens avatar Jul 06 '15 19:07 mdarens

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.

jimfb avatar Jul 06 '15 23:07 jimfb

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)?

FLGMwt avatar May 01 '16 00:05 FLGMwt

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

reznord avatar Oct 23 '16 17:10 reznord

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

pinakdas163 avatar Mar 03 '17 18:03 pinakdas163

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

nickspeal avatar Apr 01 '17 22:04 nickspeal

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.

aweary avatar Apr 09 '17 21:04 aweary

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

aweary avatar Apr 09 '17 23:04 aweary