首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >类型'State‘不满足约束'(state: any,...args: any[]) => any’

类型'State‘不满足约束'(state: any,...args: any[]) => any’
EN

Stack Overflow用户
提问于 2019-10-28 17:58:01
回答 1查看 2.8K关注 0票数 2

这可能是一个棘手的问题,但我如何处理类型记录错误TS2344?

类型'State‘不满足约束(state: any,...args: any[]) => any’。

下面是发生错误的我的sagas.ts的代码片段

代码语言:javascript
复制
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.Stateyield的关系。奇怪的是,在将类型记录更新到3.6.4版本之前,我没有出现错误。

编辑: getPageFullselectors.ts中定义为

代码语言:javascript
复制
const getPageFullInner = (state: State, id: number) => state.pagesFull.get(id);
export const getPageFull = (id: number) => (state: Top.State) 
    => getPageFullInner(foobar(state), id);

这里还定义了foobar()函数。

代码语言:javascript
复制
export const foobar = (state: State) => state.foobar;

参考文献

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-29 10:29:07

select的签名是:

代码语言:javascript
复制
export function select<Fn extends (state: any, ...args: any[]) => any>(
  selector: Fn,
  ...args: Tail<Parameters<Fn>>
): SelectEffect

因此,第一个泛型参数必须是函数类型(特别是(state: any, ...args: any[]) => any),但是您要给它State

您不需要指定泛型参数,因为它可以从参数中推断出来,所以只需编写:

代码语言:javascript
复制
select(Selectors.getPageFull(action.id))
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58596082

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档