相关疑难解决方法(0)

如何调度Action或ThunkAction(在TypeScript中,使用redux-thunk)?

说我有这样的代码:

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

interface StateTree {
  field: string;
}

function myFunc(action: Action | ThunkAction<void, StateTree, void>,
                dispatch: Dispatch<StateTree>) {
  dispatch(action); // <-- This is where the error comes from
}
Run Code Online (Sandbox Code Playgroud)

...我从TypeScript编译器中得到此错误:

ERROR in myFile.ts:x:y
TS2345: Argument of type 'Action | ThunkAction<void, StateTree, void>' is not assignable to parameter of type 'Action'.
  Type 'ThunkAction<void, StateTree, void>' is not assignable to type 'Action'.
  Property 'type' is missing in type 'ThunkAction<void, StateTree, …
Run Code Online (Sandbox Code Playgroud)

typescript redux redux-thunk

10
推荐指数
4
解决办法
1万
查看次数

标签 统计

redux ×1

redux-thunk ×1

typescript ×1