无法调用类型缺少调用签名TypeScript错误的表达式

时间:2018-07-17 12:11:46

标签: javascript typescript typescript-typings word-cloud

我无法解决类型兼容性的问题。问题在那里:

this.options.list.push(...this.cloudData.map((e: Words) => [e.word, e.size] as[string, number]) as[string, number][]);

options: Options = {
  list: [] as ListEntry
};

其中ListEntry是:

type ListEntry = [string, number];

错误是:

error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '((...items: any[]) => number) | ((...items: [string, number][]) => number)' has no compatible call signatures.

有什么想法吗?


编辑

Words类型:

export class Words {
  word: string;
  size: number;
}

1 个答案:

答案 0 :(得分:1)

解决了评论中的问题,添加为避免未解决的问题:

您对list的初始化已关闭。您的用法list应该是ListEntry

的数组
let options = {
  list: [] as ListEntry[]
};