Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support union type in React react-only props rule (#477)
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.
- Loading branch information
Showing
4 changed files
with
61 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters