Flow error - react-redux_v5.x.x - connect(mapStateToProps, mapDispatchToProps, mergeProps)(HOC)
See original GitHub issueHi, since updating Flow type definitions this morning I’m now getting this error:
lib/routes/notifications/index.js:107
107: export default connect(mapStateToProps, mapDispatchToProps, mergeProps)(Notifications);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function call. Function cannot be called on any member of intersection type
v
38: declare type Connector<OP, P> = {
39: (component: StatelessComponent<P>): ConnectedComponentClass<OP, P, void, void>;
40: <Def, St>(component: Class<React$Component<Def, P, St>>): ConnectedComponentClass<OP, P, Def, St>;
41: };
^ intersection. See lib: flow-typed/npm/react-redux_v5.x.x.js:38
Member 1:
39: (component: StatelessComponent<P>): ConnectedComponentClass<OP, P, void, void>;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function type. See lib: flow-typed/npm/react-redux_v5.x.x.js:39
Error:
39: (component: StatelessComponent<P>): ConnectedComponentClass<OP, P, void, void>;
^^^^^^^^^^^^^^^^^^^^^ function type. Callable signature not found in. See lib: flow-typed/npm/react-redux_v5.x.x.js:39
107: export default connect(mapStateToProps, mapDispatchToProps, mergeProps)(Notifications);
^^^^^^^^^^^^^ statics of React$Component
Member 2:
40: <Def, St>(component: Class<React$Component<Def, P, St>>): ConnectedComponentClass<OP, P, Def, St>;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ polymorphic type: function type. See lib: flow-typed/npm/react-redux_v5.x.x.js:40
Error:
222: export default withRouter(injectIntl(reduxForm(reduxFormProps)(Notifications)));
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `P` of function call. This type is incompatible with. See: lib/routes/notifications/component.js:222
22: declare type MergeProps<SP, DP: Object, OP: Object, P: Object> = (stateProps: SP, dispatchProps: DP, ownProps: OP) => P;
^^^^^^ object type. See lib: flow-typed/npm/react-redux_v5.x.x.js:22
connect
reference where Notifications
is a HOC:
export default connect(mapStateToProps, mapDispatchToProps, mergeProps)(Notifications);
Looking at connect definitions in react-redux_v5.x.x it seems that this:
declare function connect<S, A, OP, SP, DP, P>(
mapStateToProps: MapStateToProps<S, OP, SP>,
mapDispatchToProps: Null,
mergeProps: MergeProps<SP, DP, OP, P>,
options?: ConnectOptions
): Connector<OP, P>;
should be returning a Connector
with a $Supertype
:
declare function connect<S, A, OP, SP, DP, P>(
mapStateToProps: MapStateToProps<S, OP, SP>,
mapDispatchToProps: MapDispatchToProps<A, OP, DP>,
mergeProps: MergeProps<SP, DP, OP, P>,
options?: ConnectOptions
): Connector<OP, $Supertype<DP & OP>>;
Adding this fixes the issue for me.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Connect | React Redux
connect accepts four different parameters, all optional. By convention, they are called: mapStateToProps?: Function; mapDispatchToProps?:
Read more >React Redux connect(): When and how to use it
How does Redux connect() work? Using mapStateToProps in React Redux; Default implementation; Passing an object; Passing a function; options.
Read more >Flow | Redux | Can't pass StateProps and DispatchProps to ...
It turns out that's the flow bug with type inference. I solved this problem by explicitly adding StateProps return type to mapStateToProps ...
Read more >How to deal with failure in Redux connect ? | by Guillaume Wuip
mapStateToProps, {}, mergeProps, )(IntermediaryComponent);. Cool ! When the entity from the store is not here we now render a real error ...
Read more >Mastering mergeProps in Redux - Peanut Butter JavaScript
When you connect a component using Redux, most people are familiar with the first two arguments: mapStateToProps and mapDispatchToProps.
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
But I don’t have a
dispatch
parameter in mymapDispatchToProps
?Converting the above to have a
dispatch
parameter and type didn’t work either.@timdorr Can you re-open this please.
@timdorr Apologies for that, thanks for your reply!