一些 TypeScript 高手能帮我弄清楚为什么这段在 redux 4.0 中创建商店增强器的代码会给我类型错误吗?
最小的回购在这里。它正在创建一个无所事事的商店 ehnahcer。克隆后,通过运行安装依赖项yarn。要查看错误,请运行yarn run compile。
相关文件是
import {
StoreEnhancer,
StoreEnhancerStoreCreator,
Reducer,
DeepPartial,
AnyAction,
} from 'redux';
interface RootState {
someKey: string;
}
export const enhancer: StoreEnhancer =
(createStore: StoreEnhancerStoreCreator): StoreEnhancerStoreCreator =>
(reducer: Reducer<RootState, AnyAction>, preloadedState?: DeepPartial<RootState>) => {
const store = createStore(reducer, preloadedState);
const newDispatch: typeof store.dispatch = <A extends AnyAction>(action: A) => {
const result = store.dispatch(action);
return result;
}
return {
...store,
dispatch: newDispatch,
};
};Run Code Online (Sandbox Code Playgroud)
我得到的错误是 …
这个问题可能是约redux-observable或rxjs或两者兼而有之.
我正在寻找一种通过特定动作来启动,停止或恢复史诗的方法.例如,史诗(已经是史诗middelware的一部分)将在{type: 'START'}收到动作时处于活动状态,但在{type: 'END'}收到动作时将处于非活动状态.这可能吗?