不共享接口实现的导入组件的正确类型
Proper type for imported components that don't share an interface implementation
试图避免多次输入数组:
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[]
似乎有效,但感觉应该有更具体的内容,但我的搜索技巧让我失望了。
我认为没有比这更具体的了。由于组件本质上可以是空的 class,因此它们没有真正的接口(管道和指令也是如此)。
如果您查看 angular 源代码,您可以看到 NgModule 接口定义了具有类型 Array<Type<any>|any[]>;
的声明和导出
https://github.com/angular/angular/blob/4.4.6/packages/core/src/metadata/ng_module.ts#L115
试图避免多次输入数组:
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[]
似乎有效,但感觉应该有更具体的内容,但我的搜索技巧让我失望了。
我认为没有比这更具体的了。由于组件本质上可以是空的 class,因此它们没有真正的接口(管道和指令也是如此)。
如果您查看 angular 源代码,您可以看到 NgModule 接口定义了具有类型 Array<Type<any>|any[]>;
https://github.com/angular/angular/blob/4.4.6/packages/core/src/metadata/ng_module.ts#L115