【发布时间】:2016-02-16 14:40:49
【问题描述】:
我想在接口中声明一个替代构造函数 - baz in IFoo,但在 TypeScript 中似乎是不可能的:
interface IFoo {
bar(): boolean;
static baz(value): IFoo;
}
class Foo implements IFoo {
constructor(private qux) {}
bar(): boolean {
return this.qux;
}
static baz(value): IFoo {
return new Foo(value);
}
}
有什么方法可以做到这一点并对baz进行适当的类型检查?
【问题讨论】:
-
How to define static property in TypeScript interface 的可能副本——本质上是一样的
标签: typescript