这可能是一个棘手的问题,但我如何处理类型记录错误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
}
}问题似乎在于Top.State与yield的关系。奇怪的是,在将类型记录更新到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;参考文献
发布于 2019-10-29 10:29:07
select的签名是:
export function select<Fn extends (state: any, ...args: any[]) => any>(
selector: Fn,
...args: Tail<Parameters<Fn>>
): SelectEffect因此,第一个泛型参数必须是函数类型(特别是(state: any, ...args: any[]) => any),但是您要给它State。
您不需要指定泛型参数,因为它可以从参数中推断出来,所以只需编写:
select(Selectors.getPageFull(action.id))https://stackoverflow.com/questions/58596082
复制相似问题