【发布时间】:2021-09-27 14:19:46
【问题描述】:
在我的应用程序中,我有 BaseObjectInterface,并且我在许多接口中扩展它,例如 AObjInterface、BObjInterface 等。
然后我有一个父接口,其中包含BaseObjectInterface 数组。我希望它接受所有扩展基数的类。例如AObjInterface、BObjInterface 等。遗憾的是,它不是那样工作的。除了显式列出所有类型之外,我还能用其他方式吗?
我有什么:
list: Array<BaseObjectInterface>
我不想要的:
list: Array<AObjInterface|BObjInterface>
我想在该列表中添加什么:
[ New BaseObjectInterface(), new AObjInterface(), new BObjInterface()]
【问题讨论】:
标签: angular typescript interface polymorphism extending