我想知道这是否可以在Typescript中实现。
interface Pine {
child : <The class that implements this interface>
}
class Vine implements Pine {
child : Vine // this is enforced to be Vine, rather than any object that implements Pine.
}
我从this question知道您无法用Java做到这一点,但是TS呢?我查了一下tslang doc却没有结果。
答案 0 :(得分:0)
您可以使用泛型。 例如:
interface Base<T> {
child: T;
}
class Derived implements Base<string> {
child: string;
}
class Derived2 implements Base<number> {
child: number;
}