react-redux type error when only passing in only mapStateToProps on flow v0.55.0
See original GitHub issuePreviously on flow v0.54.1, the following code checked out fine
// @flow
import { connect, type Connector } from 'react-redux'
type State = {
val: string,
}
type OwnProps = {
other: string,
}
type Props = {
other: string,
val: string,
}
const mapStateToProps = (state: State) => {
return {
val: state.val,
}
}
const connector: Connector<OwnProps, Props> = connect(mapStateToProps)
After upgrading flow to v0.55.0, flow gives an error
Error: src/components/body/custom-events/department-transfer-container.js:29
29: const connector: Connector<OwnProps, Props> = connect(mapStateToProps)
^^^^^^^^^^^^^^^^^^^^^^^^ function call. Could not decide which case to select
29: const connector: Connector<OwnProps, Props> = connect(mapStateToProps)
^^^^^^^ intersection type
Case 3 may work:
v--------------
78: declare function connect<S, A, OP, SP>(
79: mapStateToProps: MapStateToProps<S, OP, SP>,
80: mapDispatchToProps: Null,
...:
83: ): Connector<OP, $Supertype<SP & { dispatch: Dispatch<A> } & OP>>
----------------------------------------------------------------^ polymorphic type: function type. See lib: flow-typed/npm/react-redux_v5.x.x.js:78
But if it doesn't, case 5 looks promising too:
v------------------
92: declare function connect<S, A, OP, SP, DP>(
93: mapStateToProps: MapStateToProps<S, OP, SP>,
94: mapDispatchToProps: MapDispatchToProps<A, OP, DP>,
...:
97: ): Connector<OP, $Supertype<SP & DP & OP>>
-----------------------------------------^ polymorphic type: function type. See lib: flow-typed/npm/react-redux_v5.x.x.js:92
Please provide additional annotation(s) to determine whether case 3 works (or consider merging it with case 5):
14: const mapStateToProps = (state: Object, ownProps: OwnProps) => {
^ return
I can resolve the error by passing in an empty mapDispatchToProps like so
const mapDispatchToProps = (dispatch: Dispatch<*>) => {
return {}
}
const connector: Connector<OwnProps, Props> = connect(
mapStateToProps,
mapDispatchToProps
)
but hoping there might be a way to adjust the libdef to support not passing in mapDispatchToProps like before.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:37
- Comments:23 (14 by maintainers)
Top Results From Across the Web
Flow throwing type errors for using Redux connect
I believe you'll need to add a type annotation to your dispatch . Example: function mapDispatchToProps(dispatch: Dispatch) { return ...
Read more >Redux & flow-typed で mapStateToProps に型を付ける
export default connect(mapStateToProps)(...) 参考: react-redux type error when only passing in only mapStateToProps on flow v0.55.0 #1269.
Read more >Connect: Extracting Data with mapStateToProps - React Redux
As the first argument passed in to connect , mapStateToProps is used for selecting the part of the data from the store that...
Read more >Annotating Connected Components with Flow
First, you need to explicitly annotate each connected components at file exports. This shall clear all the “implicitly instantiated” errors.
Read more >Adventures in Static Typing: React, Redux, Flow, Oh My
Inexact props are not safe. Flow has a concept of exact object types in which objects are only allowed to have an exact...
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
Annotating
mapStateToProps
has worked for me.Flow infers what version of connect to use this way.
We were wrestling with this issue, and it turned out the problem was that we weren’t declaring a return type for our
mapStateToProps
function. Adding a signature likeresolved the type error. It was just an oversight on our part.