简体   繁体   中英

What is the type for array of different modules in angular?

In angular 5 core module I'm importing external and internal modules as well.

So, I created an array of type any to hold all module objects. I used that array variable in imports and exports. My question is instead of any is there are other types we have? If So, for MODULES and COMPONENTS what type should come?

const MODULES: any[] = [
  BrowserModule,
  BrowserAnimationsModule,
  HttpClientModule,
  RouterModule,
];

const COMPONENTS: any[] = [
  HeaderComponent
];

const PROVIDERS: Provider[] = [
  NotifyService,
  RouterHelpers
];

@NgModule({
  imports: [
    ...MODULES,
  ],
  declarations: [
    ...COMPONENTS,
  ],
  providers: [
    ...PROVIDERS
  ],
  exports: [
    ...MODULES,
    ...COMPONENTS,
  ]
})

export class CoreModule {
}

from NgModule doc

  • Provider type is Provider[]
  • Declarations type is Array<Type<any> |any[]>
  • Imports type is Array<Type<any> | ModuleWithProviders |any[]> Array<Type<any> | ModuleWithProviders |any[]>
  • Exports type is Array<Type<any> | any[]> Array<Type<any> | any[]>
  • EntryComponents type is Array<Type<any> | any[]> Array<Type<any> | any[]>

Using type any[] for modules and components is valid. If you want to use something else, you can refer to the NgModule interface, which uses

  • Array<Type<any> | any[]>; for component declarations
  • Array<Type<any> | ModuleWithProviders | any[]>; for module imports

Type is a class from the angular framework ( doc )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM