Skip to content

Commit

Permalink
Merge pull request #11031 from nestjs/fix/unwrap-forward-ref
Browse files Browse the repository at this point in the history
fix(core): unwrap forward ref in module compiler
  • Loading branch information
kamilmysliwiec authored Feb 3, 2023
2 parents b92e0e9 + b73501c commit 20b545b
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions packages/core/injector/compiler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { DynamicModule, Type } from '@nestjs/common/interfaces';
import {
DynamicModule,
ForwardReference,
Type,
} from '@nestjs/common/interfaces';
import { ModuleTokenFactory } from './module-token-factory';

export interface ModuleFactory {
Expand All @@ -18,19 +22,25 @@ export class ModuleCompiler {
return { type, dynamicMetadata, token };
}

public extractMetadata(metatype: Type<any> | DynamicModule): {
public extractMetadata(
metatype: Type<any> | ForwardReference | DynamicModule,
): {
type: Type<any>;
dynamicMetadata?: Partial<DynamicModule> | undefined;
} {
if (!this.isDynamicModule(metatype)) {
return { type: metatype };
return {
type: (metatype as ForwardReference)?.forwardRef
? (metatype as ForwardReference).forwardRef()
: metatype,
};
}
const { module: type, ...dynamicMetadata } = metatype;
return { type, dynamicMetadata };
}

public isDynamicModule(
module: Type<any> | DynamicModule,
module: Type<any> | DynamicModule | ForwardReference,
): module is DynamicModule {
return !!(module as DynamicModule).module;
}
Expand Down

0 comments on commit 20b545b

Please sign in to comment.