适用于不共享接口实现的导入组件的类型

时间:2017-10-20 17:28:01

标签: 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
})
export class ExampleModule {
}

const COMPONENTS: any[]的适当类型是什么? any[]有效,但我们试图避免使用any,而object[]似乎有用,但感觉应该有更具体的内容,而我的搜索技巧让我失望。< / p>

1 个答案:

答案 0 :(得分:1)

我认为没有更具体的内容。由于Components本质上可以是一个空类,因此它们没有真正的接口(管道和指令也是如此)。

如果查看角度源代码,您可以看到NgModule接口定义了类型为Array<Type<any>|any[]>;

的声明和导出

https://github.com/angular/angular/blob/4.4.6/packages/core/src/metadata/ng_module.ts#L115