Skip to content
This repository has been archived by the owner on Sep 1, 2024. It is now read-only.

Proptypes validation of shape inside an array #181

Closed
oswagner opened this issue Apr 26, 2018 · 4 comments
Closed

Proptypes validation of shape inside an array #181

oswagner opened this issue Apr 26, 2018 · 4 comments

Comments

@oswagner
Copy link

We have an array of objects and when try to validade the shape of the object inside that array, it seems to ignore that validation.

data: PropTypes.arrayOf(PropTypes.shape({
 someValue: PropTypes.bool
})

if we change PropTypes.bool in the sample above for PropTypes.potato, like below:

data: PropTypes.arrayOf(PropTypes.shape({
 someValue: PropTypes.potato
})

We don't receive any kind of message about the error.

@ljharb
Copy link
Contributor

ljharb commented Apr 26, 2018

For the latter, you wouldn't, because PropTypes.potato is undefined. Try specifying a propType that's actually invalid but exists, like PropTypes.number when it's a boolean?

@oswagner
Copy link
Author

@ljharb Sorry, but when I gave the example of PropTypes.potato. It refers if I try to change to any other type, the same problem occurs, even if I use something like PropTypes.number 😆

@ljharb
Copy link
Contributor

ljharb commented Apr 27, 2018

@oswagner see https://jsfiddle.net/69z2wepo/182882/ - I see a propType warning in the console, and when I change "number" to "string", it no longer shows an error.

Are you sure you're using the development build of React? The production build of react doesn't check propTypes.

@ljharb
Copy link
Contributor

ljharb commented Feb 21, 2019

This might be caused by #220; closing as both a duplicate and answered.

@ljharb ljharb closed this as completed Feb 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants