How to dispatch an Action or a ThunkAction (in TypeScript, with redux-thunk)?

前端 未结 4 1585
醉话见心
醉话见心 2020-12-17 15:42

Say I have code like so:

import { Action, Dispatch } from \'redux\';
import { ThunkAction } from \'redux-thunk\';

interface StateTree {
  field: string;
}

         


        
4条回答
  •  余生分开走
    2020-12-17 16:14

    These are the correct typings: https://github.com/reduxjs/redux-thunk/blob/master/test/typescript.ts

    Most notably:

    const store = createStore(fakeReducer, applyMiddleware(thunk as ThunkMiddleware));
    

    applyMiddleware will already override the dispatch with a ThunkDispatch.

提交回复
热议问题