How can I migrate from redux-thunk 2 to 3 when using redux-mock-store 1.5.4?

94 Views Asked by At

With version 2.x.x of redux-thunk and redux-mock-store 1.5.4 this code works:

import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';

const mockStore = configureMockStore([thunk]);

...but after updating redux-thunk to 3.x.x this produces the error:

Type 'typeof import("/Users/user/Development/web-client/node_modules/redux-thunk/dist/redux-thunk")' is not assignable to type 'Middleware<{}, any, Dispatch<AnyAction>>'.
  Type 'typeof import("/Users/user/Development/web-client/node_modules/redux-thunk/dist/redux-thunk")' provides no match for the signature '(api: MiddlewareAPI<Dispatch<AnyAction>, any>): (next: Dispatch<AnyAction>) => (action: any) => any'.ts(2322)

I can certainly see why, the type information in redux-thunk.d.ts is wildly different in v3 vs v2. I haven't been able to find any information specific to using v3 with redux-mock-store.

I understand that the recommendation is to no longer use a mock store, but my immediate task is to get the packages updated.

Is there a way to use redux-thunk v3.x.x with redux-mock-store at all?

1

There are 1 best solutions below

0
WillyC On

...turned out to be easy and documented. I had to change this:

import thunk from 'redux-thunk';

to this:

import { thunk } from 'redux-thunk';

This was in the documentation but the lines looked so similar, I didn't notice the change.