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.

Flow error - react-redux_v5.x.x - connect(mapStateToProps, mapDispatchToProps, mergeProps)(HOC)

See original GitHub issue

Hi, 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:closed
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
mingvasecommented, Aug 14, 2017

But I don’t have a dispatch parameter in my mapDispatchToProps?

const mapDispatchToProps = {
    getNotifications: loadNotifications,
    saveNotifications,
    changeZone
};

Converting the above to have a dispatch parameter and type didn’t work either.

@timdorr Can you re-open this please.

0reactions
mingvasecommented, Aug 14, 2017

@timdorr Apologies for that, thanks for your reply!

Read more comments on GitHub >

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

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