【发布时间】:2016-03-14 02:59:45
【问题描述】:
在 TypeScript 中有没有办法用泛型类型扩展一个类?请参阅我的“假设场景”示例,其中我希望我的班级拥有名为“品种”(或其他)的属性:
interface dog {
breed: string;
}
export class animal<T> extends T {
legs: number;
}
export class main {
private mydog: animal = new animal<dog>();
constructor() {
this.mydog.legs = 4;
this.mydog.breed = "husky"; //<-- not conventionally possible, but basically want to acheive this
}
}
【问题讨论】:
标签: generics typescript