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

fix: support union type in React react-only props rule #477

Merged
merged 1 commit into from Apr 16, 2021
Merged

fix: support union type in React react-only props rule #477

merged 1 commit into from Apr 16, 2021

Conversation

mrtnzlml
Copy link
Contributor

This change fixes the following (simplified) example from our application:

type Props =
  | {
      +children: React$Node,
      +title: React$Node,
      +withHiddenTitle?: false,
    }
  | {
      +children: React$Node,
      +title?: React$Node,
      +withHiddenTitle: true,
    };

const props: Props = {children:"", withHiddenTitle: true}
props.title = ""; // correct Flow error

Flow correctly throws the following error:

14: props.title = "";
          ^ Cannot assign empty string to `props.title` because property `title` is not writable. [cannot-write]

However, flowtype/require-readonly-react-props Eslint rule throws the following (incorrect) error:

Props must be $ReadOnly

For simplification, all of the objects in the union must be readonly even though it's probably not a strict requirement in Flow. This can be improved later when needed.

This change fixes the following (simplified) example from our application:

```
type Props =
  | {
      +children: React$Node,
      +title: React$Node,
      +withHiddenTitle?: false,
    }
  | {
      +children: React$Node,
      +title?: React$Node,
      +withHiddenTitle: true,
    };

const props: Props = {children:"", withHiddenTitle: true}
props.title = ""; // correct Flow error
```

Flow correctly throws the following error:

```
14: props.title = "";
          ^ Cannot assign empty string to `props.title` because property `title` is not writable. [cannot-write]
```

However, `flowtype/require-readonly-react-props` Eslint rule throws the following (incorrect) error:

```
Props must be $ReadOnly
```

For simplification, all of the objects in the union must be readonly even though it's probably not a strict requirement in Flow. This can be improved later when needed.
@gajus gajus merged commit 7cabcda into gajus:master Apr 16, 2021
@gajus
Copy link
Owner

gajus commented Apr 16, 2021

🎉 This PR is included in version 5.7.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@gajus gajus added the released label Apr 16, 2021
@mrtnzlml mrtnzlml deleted the react_react_only_props_union_type branch April 16, 2021 20:27
mrtnzlml added a commit to adeira/universe that referenced this pull request Apr 16, 2021
kodiakhq bot pushed a commit to adeira/universe that referenced this pull request Apr 17, 2021
adeira-github-bot pushed a commit to adeira/eslint-config-adeira that referenced this pull request Apr 17, 2021
This release includes some fixes for our codebase, see:

- gajus/eslint-plugin-flowtype#477
- gajus/eslint-plugin-flowtype#478

adeira-source-id: a16fb4f4e7da1a952452a75cb4c4cc58f92e69bf
adeira-github-bot pushed a commit to adeira/sx-design that referenced this pull request Apr 17, 2021
This release includes some fixes for our codebase, see:

- gajus/eslint-plugin-flowtype#477
- gajus/eslint-plugin-flowtype#478

adeira-source-id: a16fb4f4e7da1a952452a75cb4c4cc58f92e69bf
mrtnzlml added a commit to mrtnzlml-archive/kochka.com.mx that referenced this pull request May 4, 2021
This release includes some fixes for our codebase, see:

- gajus/eslint-plugin-flowtype#477
- gajus/eslint-plugin-flowtype#478

adeira-source-id: a16fb4f4e7da1a952452a75cb4c4cc58f92e69bf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants