react-redux libdef causes errors with maybe-typed props
See original GitHub issueI have some presentational components that expect a maybe-typed boolean readOnly
. This is purposefully optional so consumers don’t have to say readOnly={false}
.
I have some container components that sometimes pass down a readOnly
boolean, but theirs is not a maybe type. For example:
This pattern breaks in my codebase:
Error ---------------------------------------------------
QuestionSelect.js:41:13
undefined [1] is incompatible with boolean [2].
41| readOnly?: boolean
^^^^^^^ [1]
References:
QuestionSelectContainer.js:9:45
9| type Props = { value: QuestionId, readOnly: boolean };
^^^^^^^ [2]
Passing readOnly
to a component expecting readOnly?
should not error.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:11 (10 by maintainers)
Top Results From Across the Web
Issues with react-redux · Issue #5343 · facebook/flow - GitHub
Flow correctly gives me an error about data being the wrong type if I only call connect(mapStateToProps) . If I call connect(mapStateToProps, { ......
Read more >reactjs - Flow error "props is incompatible with empty" when ...
js [2] 110│ CP: $Diff<ElementConfig<Com>, RSP>,. Isn't props in 1 already empty?? I am using flow-typed as you can state in the error....
Read more >Usage with TypeScript - React Redux
Usage > TypeScript: how to correctly type React Redux APIs. ... This causes errors if you have multiple copies of @types/react in your ......
Read more >Useful Patterns by Use Case - React TypeScript Cheatsheets
Both Props and State can take advantage of the same generic types, although it probably makes more sense for Props than for State....
Read more >Adventures in Static Typing: React, Redux, Flow, Oh My
*/ } // building is optional! |};<input value={this.props.building.defaultLocale} …> Naturally, this fixed lots of “Cannot read ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think this is the same issue as https://github.com/flowtype/flow-typed/issues/1997 We’re running into an issue where doing
$Diff
causes the flow error to look like it’s being evaluated backwards.Example
This may be related to the disclaimer here: https://flow.org/en/docs/types/utilities/#toc-diff
This has been filed as an issue in the main flow repo https://github.com/facebook/flow/issues/6149
Ok now I got it, thanks! Looks like the flow check is somewhat other way around in this case. It might be possible to solve with a bit of reordering of the types in the libdefs. I could check it out once I have time, but can’t promise anything.