【发布时间】:2018-12-25 03:18:15
【问题描述】:
我无法解决类型兼容性的问题。问题出在:
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;
}
【问题讨论】:
-
这可能是因为
options.list期望一个字符串作为它的第一个条目,但你给它一个数组。 -
你能添加类型
Words吗? -
现在添加了,抱歉
-
什么是选项类型。您的代码主要对我有用,唯一的问题是列表字段应该是
list: [] as ListEntry[]typescriptlang.org/play/… -
@TitianCernicova-Dragomir 感谢它的工作
标签: javascript typescript typescript-typings word-cloud