【发布时间】:2020-07-24 07:08:20
【问题描述】:
我正在尝试推断 RootState 的类型,但在尝试在选择器中使用它时出现此错误:
const tagsSelector = (state: RootState) => state.tags;
TS2339: Property 'tags' does not exist on type 'CombinedState<{ tags: CombinedState<{ tagsSet: TagsState; }>; } | { queue: CombinedState<{ clientCard: ClientCardState; clientCardTasks: ClientCardTasksState; }>; }>'. Property 'tags' does not exist on type '{ readonly [$CombinedState]?: undefined; } & { queue: CombinedState<{ clientCard: ClientCardState; clientCardTasks: ClientCardTasksState; }>; }'.
我推断的RootState类型
const typedReducers = typedModules.map(m => m.getTypedReducers() ).reduce((accum, r) => {
return {...accum, ...r}
});
const rootTypedReducers = combineReducers(typedReducers);
export type RootState = ReturnType<typeof rootTypedReducers>;
getTypedReducers() 只返回每个模块的根减速器
getTypedReducers() {
return {tags: combineReducers({
tagsSet: tagsReducers,
})};
}
但是,如果我只使用一个模块,那么一切正常。
【问题讨论】:
标签: reactjs typescript redux redux-toolkit