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-covariant-props #1454

Closed
julienw opened this issue Sep 28, 2017 · 4 comments · Fixed by #2110
Closed

Add a rule prefer-covariant-props #1454

julienw opened this issue Sep 28, 2017 · 4 comments · Fixed by #2110

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 write to the props object, like this: this.props.prop1 = 'foo' which is to be avoided.
To force this with flow, the solution is to use covariant properties:

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.

@julienw
Copy link
Contributor Author

julienw commented Sep 28, 2017

Yeah I hesitated between filing this or in eslint-plugin-flowtype, but I thought it was more react-specific than flow-specific :)

@EvHaus
Copy link
Collaborator

EvHaus commented Jan 4, 2019

Closing this as a duplicate of #1869

@EvHaus EvHaus closed this as completed Jan 4, 2019
@julienw
Copy link
Contributor Author

julienw commented Jan 4, 2019

👍

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.

3 participants