diff --git a/packages/common/interfaces/modules/module-metadata.interface.ts b/packages/common/interfaces/modules/module-metadata.interface.ts index 9d6699cba74..2cc3ca27d2c 100644 --- a/packages/common/interfaces/modules/module-metadata.interface.ts +++ b/packages/common/interfaces/modules/module-metadata.interface.ts @@ -16,7 +16,7 @@ export interface ModuleMetadata { * Optional list of imported modules that export the providers which are * required in this module. */ - imports?: Array< + imports?: ReadonlyArray< Type | DynamicModule | Promise | ForwardReference >; /** @@ -33,7 +33,7 @@ export interface ModuleMetadata { * Optional list of the subset of providers that are provided by this module * and should be available in other modules which import this module. */ - exports?: Array< + exports?: ReadonlyArray< | DynamicModule | Promise | string diff --git a/packages/core/injector/container.ts b/packages/core/injector/container.ts index e9418a1b8a8..8d78c6da0db 100644 --- a/packages/core/injector/container.ts +++ b/packages/core/injector/container.ts @@ -173,7 +173,10 @@ export class NestContainer { await this.addDynamicModules(imports, scope); } - public async addDynamicModules(modules: any[], scope: Type[]) { + public async addDynamicModules( + modules: ReadonlyArray, + scope: Type[], + ) { if (!modules) { return; } diff --git a/packages/core/test/injector/container.spec.ts b/packages/core/test/injector/container.spec.ts index e9916a4aa40..8a3da3441a3 100644 --- a/packages/core/test/injector/container.spec.ts +++ b/packages/core/test/injector/container.spec.ts @@ -210,6 +210,16 @@ describe('NestContainer', () => { expect(addModuleSpy.called).to.be.true; }); }); + describe('when array is readonly', () => { + it('should call "addModule"', () => { + const addModuleSpy = sinon.spy(container, 'addModule'); + + const readonlyModules: ReadonlyArray = Object.freeze([Test]); + container.addDynamicModules(readonlyModules, []); + + expect(addModuleSpy.called).to.be.true; + }); + }); }); describe('get applicationConfig', () => {