尽量避免多次输出数组:
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>
答案 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