Skip to content

Commit 7172671

Browse files
KamilKamil
authored andcommitted
Merge branch 'master' of https://github.com/nestjs/nest
2 parents 294e269 + 51d5be4 commit 7172671

1 file changed

Lines changed: 18 additions & 16 deletions

File tree

packages/core/nest-application-context.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import iterate from 'iterare';
2-
import { ModuleTokenFactory } from './injector/module-token-factory';
3-
import { NestContainer, InstanceWrapper } from './injector/container';
1+
import { INestApplicationContext, OnModuleInit } from '@nestjs/common';
42
import { Type } from '@nestjs/common/interfaces/type.interface';
53
import {
64
isFunction,
75
isNil,
86
isUndefined,
97
} from '@nestjs/common/utils/shared.utils';
10-
import { INestApplicationContext, OnModuleInit } from '@nestjs/common';
11-
import { Module } from './injector/module';
12-
import { UnknownModuleException } from './errors/exceptions/unknown-module.exception';
8+
import iterate from 'iterare';
139
import { UnknownElementException } from './errors/exceptions/unknown-element.exception';
10+
import { UnknownModuleException } from './errors/exceptions/unknown-module.exception';
11+
import { InstanceWrapper, NestContainer } from './injector/container';
12+
import { Module } from './injector/module';
13+
import { ModuleTokenFactory } from './injector/module-token-factory';
1414

1515
export class NestApplicationContext implements INestApplicationContext {
1616
private readonly moduleTokenFactory = new ModuleTokenFactory();
@@ -40,22 +40,24 @@ export class NestApplicationContext implements INestApplicationContext {
4040
return new NestApplicationContext(this.container, scope, selectedModule);
4141
}
4242

43-
public get<T>(
44-
typeOrToken: Type<T> | string | symbol,
43+
public get<TInput = any, TResult = TInput>(
44+
typeOrToken: Type<TInput> | string | symbol,
4545
options: { strict: boolean } = { strict: false },
46-
): T {
46+
): TResult {
4747
if (!(options && options.strict)) {
48-
return this.find<T>(typeOrToken);
48+
return this.find<TInput, TResult>(typeOrToken);
4949
}
50-
return this.findInstanceByPrototypeOrToken<T>(
50+
return this.findInstanceByPrototypeOrToken<TInput, TResult>(
5151
typeOrToken,
5252
this.contextModule,
5353
);
5454
}
5555

56-
public find<T>(typeOrToken: Type<T> | string | symbol): T {
56+
public find<TInput = any, TResult = TInput>(
57+
typeOrToken: Type<TInput> | string | symbol,
58+
): TResult {
5759
this.initFlattenModule();
58-
return this.findInstanceByPrototypeOrToken<T>(
60+
return this.findInstanceByPrototypeOrToken<TInput, TResult>(
5961
typeOrToken,
6062
this.contextModuleFixture,
6163
);
@@ -90,10 +92,10 @@ export class NestApplicationContext implements INestApplicationContext {
9092
return !isUndefined((instance as OnModuleInit).onModuleInit);
9193
}
9294

93-
private findInstanceByPrototypeOrToken<T>(
94-
metatypeOrToken: Type<T> | string | symbol,
95+
private findInstanceByPrototypeOrToken<TInput = any, TResult = TInput>(
96+
metatypeOrToken: Type<TInput> | string | symbol,
9597
contextModule,
96-
): T {
98+
): TResult {
9799
const dependencies = new Map([
98100
...contextModule.components,
99101
...contextModule.routes,

0 commit comments

Comments
 (0)