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

Nested properties and prop-types #105

Closed
mathieumg opened this issue Jun 10, 2015 · 2 comments
Closed

Nested properties and prop-types #105

mathieumg opened this issue Jun 10, 2015 · 2 comments

Comments

@mathieumg
Copy link
Contributor

mathieumg commented Jun 10, 2015

Is it an oversight or a limitation that for the react/prop-types rule, no warning is emitted for missing nested properties.

For example, with:

propTypes: {
  a: React.PropTypes.shape({
    b: React.PropTypes.shape({
      c: React.PropTypes.func
    })
  })
}

I get no warning when I use this.props.a.b.d.

Thank you!

@Cellule
Copy link
Contributor

Cellule commented Jun 15, 2015

If this is something we want to add support for. I fiddled with it a bit tonight and I got something working for quite a few nested cases.
It checks for shape arrayOf objectOf oneOfType and instanceOf.
I need to do some additional testing, but so far it look pretty solid. I can event do checks like
this.props.a[0][someVar].e and give warning about e if the propTypes are

propTypes = {
  a: React.PropTypes.arrayOf(
    React.PropTypes.objectOf(
      React.PropTypes.shape({
        b: React.PropTypes.string
      })
    )
  )
};

Let me know if you want me to polish it.

In case you're interested to see what I did so far
master...Cellule:prop_type

@yannickcr
Copy link
Member

yannickcr commented Jun 15, 2015

Wow. That's definitely something we're interested in. I did not dive in your code yet but it seems great so far.

You can polish it, I will be very happy to merge it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants