【发布时间】:2015-03-28 00:51:00
【问题描述】:
我有课:
export class LinkedList<t>
我目前使用以下方法创建一个超类:
export class ListBody extends collections.LinkedList<Element>
这一切都很好。但是,我在其他几个类中声明了这个类,并且在每个地方,它实际上只需要几个 Element 的超类。所以我想在其他地方,而不是声明:
this.body = new moduleListBody.ListBody();
声明:
this.body = new moduleListBody.ListBody<ElementOne | ElementTwo>();
有没有办法做到这一点?我不能跳过 ListBody 类,因为其中有大量对 Element 对象进行操作的代码。
更新:示例
export class Element {
}
export class LinkedList<t> {
public add(index : number, value : t);
public add(index : number, collection : LinkedList<t>);
public add(index : number, collection : t[]);
add(index : number, arg : t | LinkedList<t> | t[]) {
}
}
export class ListBody <T extends Element> extends LinkedList<T> {
public fubar(): void {
var element = new Element();
this.add(0, element);
}
}
【问题讨论】:
标签: typescript1.4