在我的应用程序中,我有BaseObjectInterface
,我扩展它在许多接口,如AObjInterface
,BObjInterface
等。然后我有父接口,其中有BaseObjectInterface
数组。我想让它接受所有扩展base 1的类。例如AObjInterface
,BObjInterface
等。遗憾的是,事实并非如此。除了显式列出所有类型之外,还有其他方法吗?
我有的:list: Array<BaseObjectInterface>
我不想要的:list: Array<AObjInterface|BObjInterface>
我想在列表中添加的内容:[ New BaseObjectInterface(), new AObjInterface(), new BObjInterface()]
如果,如您所说,BaseObjectInterface是AObjInterface和BObjInterface的父类,那么类型可以只是Array<BaseObjectInterface>
。TypeScript Playground示例