-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
no-unused-prop-types
: All fields reported as unused with PropTypes.arrayOf(PropTypes.exact)
#2850
Comments
I definitely would not expect them to behave the same - in a shape, all properties are optional unless |
Sorry, I think I've explained myself badly. It's unexpected that case B above produces an error for Am I misunderstanding something? |
ahhh, yes, I agree - case B should not be producing any warnings. |
I'm trying to take a look at this, but I'm seeing something weird. const Comp = ({ a, c, e, g }) => <div>
{a.map((props) => <div>{props.b}</div>)}
{c.map(({ d }) => <div>{d}</div>)}
{e.map((props) => <div>{props.f}</div>)}
{g.map(({ h }) => <div>{h}</div>)}
</div>;
Comp.propTypes = {
a: PropTypes.arrayOf(PropTypes.shape({ b: PropTypes.string })),
c: PropTypes.arrayOf(PropTypes.shape({ d: PropTypes.string })),
e: PropTypes.arrayOf(PropTypes.exact({ f: PropTypes.string })),
g: PropTypes.arrayOf(PropTypes.exact({ h: PropTypes.string })),
}; Using the versions and config from my first post, the above code results in one error when running
However, If I add the same code to
The currently published version ( EDIT: class Comp {
render() {
return (<div>
{this.props.a.map((props) => <div>{props.b}</div>)}
{this.props.c.map(({ d }) => <div>{d}</div>)}
{this.props.e.map((props) => <div>{props.f}</div>)}
{this.props.g.map(({ h }) => <div>{h}</div>)}
</div>);
}
}
Comp.propTypes = {
a: PropTypes.arrayOf(PropTypes.shape({ b: PropTypes.string })),
c: PropTypes.arrayOf(PropTypes.shape({ d: PropTypes.string })),
e: PropTypes.arrayOf(PropTypes.exact({ f: PropTypes.string })),
g: PropTypes.arrayOf(PropTypes.exact({ h: PropTypes.string })),
}; |
It is a regression if destructured props no longer work, and it seems reasonable to ensure they do work for both exact and shape. |
It seems like when a list of objects is typed using
PropTypes.arrayOf(PropTypes.exact({ ... }))
all properties of the inner object are reported as not in use byno-unused-prop-types
regardless of them being used or not. This is not the case withPropTypes.arrayOf(PropTypes.shape({ ... }))
.I would expectPropTypes.arrayOf(PropTypes.exact)
andPropTypes.arrayOf(PropTypes.shape)
to behave the same when checking for unused propertiesI would expect the two below cases to have no errors as they are very similar. However, case A has no errors, while case B reports that
a.*.b
is not in use.How to reproduce
Case A:
No errors reported
Case B:
Error:
'a.*.b' PropType is defined but prop is never used
.eslintrc.json
package.json
The text was updated successfully, but these errors were encountered: