我希望有一个变量来存储类实例数组,但是我想将数据类型指定为从“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());
提前致谢。