【发布时间】:2020-01-29 13:02:21
【问题描述】:
在我的 index.tsx 中,我创建了 redux 存储
import { createStore, Store } from 'redux';
...
const store: Store = createStore(reducers, {});
现在我尝试添加 composeWithDevTools
import { createStore, Store, compose } from 'redux';
import { composeWithDevTools } from 'redux-devtools-extension';
...
const store: Store = createStore(reducers, {}, compose(composeWithDevTools()));
我得到的是错误
Type 'Store<CombinedState<{ general: any; }>, StoreAction>' is not assignable to type 'Store<any, AnyAction>'.
Types of property 'dispatch' are incompatible.
Type 'Dispatch<StoreAction>' is not assignable to type 'Dispatch<AnyAction>'.
Type 'AnyAction' is not assignable to type 'StoreAction'. TS2322
看起来它与我的 StoreAction 类型有某种关系。 在我的减速器中,我有以下内容
export default (state: GeneralState = initialState, action: StoreAction) => {
...
};
StoreAction 是
type StoreAction = {
type: string;
payload: any;
};
而且这个 StoreAction type 与 AnyAction interface 不兼容。我不明白如何从 TypeScript 的角度正确修复它。
有什么办法可以解决这个错误吗?
【问题讨论】:
标签: reactjs typescript redux