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

Add a rule prefer-exact-props #1455

Closed
julienw opened this issue Sep 28, 2017 · 2 comments · Fixed by #1547
Closed

Add a rule prefer-exact-props #1455

julienw opened this issue Sep 28, 2017 · 2 comments · Fixed by #1547

Comments

@julienw
Copy link
Contributor

julienw commented Sep 28, 2017

With react and flow, it's very common to type props like this:

type Props = {
  prop1: string,
  prop2: number
};

However this makes it possible to pass other props as well, as by default objects in Flow are not exact. So this can hide an issue where the developer removed a prop but the caller still use it:

<Component prop1='foo' prop2={42} prop3='bar' />

Or made a typo (this example is possible is prop2 is optional):

<Component prop1='foo' porp2={42} />

To fix this with flow, the solution is to use exact objects:

type Props = {|
  prop1: string,
  prop2: number
|};

It would be useful to have an eslint rule to force this pattern.

@ljharb
Copy link
Member

ljharb commented Sep 28, 2017

I'm a bit hesitant to have Flow-only rules in a non-flow-specific eslint plugin, but I agree that such a rule would be a good thing to have if using Flow.

With PropTypes, you can use https://npmjs.com/prop-types-exact to get the same behavior; maybe the rule could recommend both?

@julienw
Copy link
Contributor Author

julienw commented Sep 28, 2017

Ah yep, good idea !

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

Successfully merging a pull request may close this issue.

2 participants