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

prop-types does mark nested destructured props as being used #296

Closed
kolodny opened this issue Nov 5, 2015 · 5 comments · Fixed by #2300
Closed

prop-types does mark nested destructured props as being used #296

kolodny opened this issue Nov 5, 2015 · 5 comments · Fixed by #2300
Labels

Comments

@kolodny
Copy link

kolodny commented Nov 5, 2015

Assume I have a propTypes as follows:

propTypes: {
  foo: PropTypes.number,
  bar: PropTypes.shape({
    faz: PropTypes.number,
    qaz: PropTypes.object,
  }),
};

I would want accessing this.props.bar.faz to not generate an error, while this.props.bar.nope to generate an error.

This may be tricky because PropTypes.shape is technically a black box, but when used with something like recursive from https://github.com/kolodny/zan it would make sense

@yannickcr
Copy link
Member

Nested prop-types are supported since v2.6.0, your example will correctly generate an error for bar.nope but not for bar.faz.

@kolodny
Copy link
Author

kolodny commented Nov 5, 2015

Ahh so it would seem. I was doing shape() and not PropTypes.shape(), is there a way to support just .shape()?

@yannickcr
Copy link
Member

Not for now, but I can consider this possibility.

@ianmstew
Copy link

ianmstew commented Dec 3, 2015

In version 3.11.2 I can confirm dot-accessed nested props are checked, but destructured nested props are not. Should I open a new issue on this?

For example, const nope = this.props.bar.nope will generate an error, but const {bar:{nope}} = this.props will not.

@lencioni
Copy link
Collaborator

I have also confirmed that dot-accessed nested props are checked but nested destructured props are not. Here's a repro case:

 function Foo(props) {
   const { bar: { nope } } = props;
   return <div test={nope} />;
 }

 Foo.propTypes = {
   foo: PropTypes.number,
   bar: PropTypes.shape({
     faz: PropTypes.number,
     qaz: PropTypes.object,
   }),
 };

@ianmstew don't worry about opening a new issue, I'll just modify this one.

@lencioni lencioni added bug and removed enhancement labels Aug 20, 2016
@lencioni lencioni changed the title prop-types nested checking prop-types does mark nested destructured props as being used Aug 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

4 participants