question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

react-redux libdef causes errors with maybe-typed props

See original GitHub issue

I 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:

https://flow.org/try/#0C4TwDgpgBACgTgezAZygXigbynCBDAEwHkA7AGxAH4AuKAIwQTPxKgF8AoUSKAZWDzAI8JKgzZchUhVoMmLdhw4BjBCWTAoAWxD9BEWnqEiU6LDnzFyIWgDM8ZZNE6r1mnSeS1PZiZek22roCQgB0klYU7EA

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:open
  • Created 5 years ago
  • Reactions:1
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
thenanyucommented, May 30, 2018

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

Note that $Diff<A, B> will error if the object you are removing properties from does not have the property being removed, i.e. if B has a key that doesn’t exist in A

This has been filed as an issue in the main flow repo https://github.com/facebook/flow/issues/6149

0reactions
villesaucommented, May 21, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found