【发布时间】:2020-12-31 10:42:26
【问题描述】:
我的代码中不能有 any 作为类型,所以在 Dispatch<any> 的位置,我收到一条错误消息:Unexpected any。指定不同的类型。
当我输入<unknown> 只是为了查看它是否会停止出错时,我得到:类型“未知”不满足约束“操作”。
有谁知道 Dispatch 的类型是什么?
export function doSomething(options: doSomethingOptions): ActionCreator<AnyAction> {
return (dispatch: Dispatch<any>): Action => {
............
};
}
【问题讨论】:
-
来自redux--> import { Action, Dispatch, AnyAction, ActionCreator } from 'redux';
-
是的,我添加了它们,谢谢
-
另外,
@types包有type definitions for various Redux packages,你安装过吗? -
我在 package.json 中看到了@types/redux-mock-store,但仅此而已,似乎无关
-
我认为 type 是您要发送的东西的类型,但同样,我不使用它。 This 可能会有所帮助。编码愉快!
标签: typescript redux types react-redux redux-thunk