Angular 不共享接口实现的导入组件的正确类型
尝试避免多次键入数组:Angular 不共享接口实现的导入组件的正确类型,angular,typescript,typescript2.0,Angular,Typescript,Typescript2.0,尝试避免多次键入数组: import { ComponentA } from './components/A.component'; import { ComponentB } from './components/B.component'; const COMPONENTS: any[] = [ ComponentA, ComponentB ]; @NgModule({ declarations: COMPONENTS, exports: COMPONENTS }) exp
import { ComponentA } from './components/A.component';
import { ComponentB } from './components/B.component';
const COMPONENTS: any[] = [
ComponentA,
ComponentB
];
@NgModule({
declarations: COMPONENTS,
exports: COMPONENTS
})
export class ExampleModule {
}
常量组件的适当类型是什么:any[]?any[]可以工作,但我们正在努力避免使用any,object[]似乎可以工作,但感觉应该有更具体的东西,我的搜索技能让我失望。我认为没有更具体的东西。由于组件本质上可以是一个空类,因此它们没有与管道和指令相同的真正接口
如果您查看angular源代码,您可以看到NgModule接口定义声明和导出,因为将类型ArrayAs放在一边,如果可能的话,我宁愿不使用标记接口。