【发布时间】:2016-08-02 03:24:09
【问题描述】:
我试图重载实现接口的类的构造函数,但出现以下错误:
[0] app/foo.ts(12,5): error TS2394: Overload signature is not compatible with function implementation.
类
export interface Item {
time: number;
}
export class Foo implements Item {
public time: number;
public name: string;
constructor();
constructor(
time: number,
name: string
) {
this.time = id || -1
this.name = name || ""
};
}
我发现了其他类似的问题 (Constructor overload in TypeScript),但我遗漏了一些东西,因为它不起作用。打字稿版本是 1.8.9。
【问题讨论】: