Closed
Description
Consider the following contrived example:
type PropsFlowType = {|
...
primaryAction: {
action: () => void, // here
icon: string, // here
title: string, // here
},
...
|};
const StatelessComponent = ({ primaryAction, ... }: PropsFlowType) => (
...
<SomeComponent
action={primaryAction.action}
icon={primaryAction.icon}
title={primaryAction.title}
/>
...
);
Eslint will complain at the lines marked // here
that these values are not used, even though they are in-fact used. Perhaps a compatibility issue with Flow?
Activity
ljharb commentedon Mar 17, 2017
I'm not sure how Flow works here with nested shapes, but in PropTypes, it'd need to be
PropTypes.shape({ … })
, not an object literal. It's possible that this plugin doesn't work with nested object flow types?What happens if you make
primaryAction
its own, separate type?joncursi commentedon Mar 17, 2017
Hmm. Breaking out primaryAction into it's own type results in the same error:
joncursi commentedon Mar 17, 2017
Interestingly enough, I found that adding
= {}
after the props function argument takes away these errors:I'm really not sure what this is doing, though. It seems more like a hack than a solution because now, if I actually do forget to use
primaryAction.something
, or any other prop for that matter, ESLint no longer warns me because it has been tricked by the= {}
to believe everything is being used. Nothing will flag anymore.billyvg commentedon Apr 17, 2017
Is this perhaps related to #587?
prop-types
: handle variables defined as props #2301Update eslint-plugin-react to the latest version 🚀 (#88)
46 remaining items