使用打字稿将异步操作发送到 redux dispatch

Sending async action to redux dispatch using typescript

当我尝试在 redux 中调度异步操作时遇到问题。 我正在使用 redux-thunk 来处理我的异步中间件。

我有一个像这样的异步操作函数:

function async() {
    return dispatch => {
        dispatch(req());

        setTimeout(function() {
            dispatch(rec());
        }, 2000);
    }
}

这是我的 createStore 语句:

const store = createStore(
    reducer,
    applyMiddleware(thunk)
);

当我尝试这样做时:store.dispatch(async()) 我遇到了这种错误:

error TS2345: Argument of type '(dispach: any) => void' is not assignable to parameter of type 'Action'

代码本身在我使用 javascript 时有效。

解决方案是从 definitelytyped 下载 redux typings: typings i redux --ambient