Skip to content

Nested properties and prop-types #105

Closed
@mathieumg

Description

@mathieumg
Contributor

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!

Activity

Cellule

Cellule commented on Jun 15, 2015

@Cellule
Contributor

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

yannickcr commented on Jun 15, 2015

@yannickcr
Member

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

added a commit that references this issue on Jun 17, 2015

Merge pull request #112 from Cellule/nested_prop_types

c0ed5fc

36 remaining items

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @yannickcr@mathieumg@Cellule

        Issue actions

          Nested properties and prop-types · Issue #105 · jsx-eslint/eslint-plugin-react