【发布时间】:2020-02-24 00:33:46
【问题描述】:
这可能是一个菜鸟问题,但是我该如何处理 Typescript 错误 TS2344?
类型 'State' 不满足约束 '(state: any, ...args: any[]) => any'。
这是我的sagas.ts发生错误的代码片段
function* loadPageFull(action: Actions.LoadPageFullAction ) {
if (!action.id)
return;
const currentPageFull: Interfaces.PageFull =
yield (select<Top.State>(Selectors.getPageFull(action.id))); // <-- error occurs here
if (!currentPageFull || action.forceReload) {
// here we query the API of the backend and return some JSON
}
}
问题似乎是与yield 一致的Top.State。奇怪的是,我在将 Typescript 更新到 3.6.4 版本之前没有出现错误。
编辑:getPageFull 在selectors.ts 中定义为
const getPageFullInner = (state: State, id: number) => state.pagesFull.get(id);
export const getPageFull = (id: number) => (state: Top.State)
=> getPageFullInner(foobar(state), id);
foobar() 函数也在那里定义
export const foobar = (state: State) => state.foobar;
参考文献
【问题讨论】:
标签: reactjs typescript redux-saga