包含扩展基类的类实例的TypeScript变量

时间:2016-12-05 11:45:56

标签: javascript typescript types

我希望有一个变量来存储类实例数组,但是我想将数据类型指定为从“base”类继承的任何数据类型。通过示例更好地证明了这一点:

class Mom { } //Base class
class Son extends Mom { }
class Daughter extends Mom { }

//What is the syntax for this?
let example : <T extends Mom>T[] = [ ]; //This array should store anyting that extends 'Mom'

//The this would be possible
example.push(new Mom());
example.push(new Son());
example.push(new Daughter());

提前致谢。

0 个答案:

没有答案