我想要一个变量来存储类实例数组,但我想将数据类型指定为从“基”类继承的任何类型。通过示例可以更好地证明这一点:
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());
Run Code Online (Sandbox Code Playgroud)
提前致谢。
| 归档时间: |
|
| 查看次数: |
1988 次 |
| 最近记录: |