Is there any way to correctly dispatch a Thunk from a store created with redux-mock-store ? Right now I am forced to use any type assertion
store.dispatch<any>(getCommissions());
As dispatch expects to provide plain Action
[ts]
Argument of type '(dispatch: ThunkDispatch<IRootState, undefined,
AnyAction>, getState: () => IRootState) => void' is not assignable to parameter of type 'AnyAction'.
Property 'type' is missing in type '(dispatch: ThunkDispatch<IRootState, undefined, AnyAction>, getState: () => IRootState) => void'.
Code fragment for getCommisions()
export function getCommissions() {
return (dispatch: ThunkDispatch<IRootState, undefined, AnyAction>, getState: () => IRootState) => { ... }
The
createMockStorefunction that is the default export ofredux-mock-storeaccepts generic types<S, DispatchExts>whereSis the definition of your Redux state, andDispatchExtsis a union of (or single) additionalDispatchsignatures for any added Redux middleware.So the way to set this up is to import
ThunkDispatchfromredux-thunk, which accepts its own generic arguments of<State, ExtraArgument, Action>and pass that in as theDispatchExtsargument tocreateMockStore.Here's an abbreviated example:
Hope that helps you!
My current versions:
redux 4.0.0redux-thunk 2.3.0redux-mock-store 1.5.3typescript 2.9.2ThunkDispatchdefintion https://github.com/reduxjs/redux-thunk/blob/master/index.d.tscreateMockStoredefinition https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/redux-mock-store/index.d.ts