|
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'; |
4 | 2 | import { Type } from '@nestjs/common/interfaces/type.interface'; |
5 | 3 | import { |
6 | 4 | isFunction, |
7 | 5 | isNil, |
8 | 6 | isUndefined, |
9 | 7 | } 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'; |
13 | 9 | 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'; |
14 | 14 |
|
15 | 15 | export class NestApplicationContext implements INestApplicationContext { |
16 | 16 | private readonly moduleTokenFactory = new ModuleTokenFactory(); |
@@ -40,22 +40,24 @@ export class NestApplicationContext implements INestApplicationContext { |
40 | 40 | return new NestApplicationContext(this.container, scope, selectedModule); |
41 | 41 | } |
42 | 42 |
|
43 | | - public get<T>( |
44 | | - typeOrToken: Type<T> | string | symbol, |
| 43 | + public get<TInput = any, TResult = TInput>( |
| 44 | + typeOrToken: Type<TInput> | string | symbol, |
45 | 45 | options: { strict: boolean } = { strict: false }, |
46 | | - ): T { |
| 46 | + ): TResult { |
47 | 47 | if (!(options && options.strict)) { |
48 | | - return this.find<T>(typeOrToken); |
| 48 | + return this.find<TInput, TResult>(typeOrToken); |
49 | 49 | } |
50 | | - return this.findInstanceByPrototypeOrToken<T>( |
| 50 | + return this.findInstanceByPrototypeOrToken<TInput, TResult>( |
51 | 51 | typeOrToken, |
52 | 52 | this.contextModule, |
53 | 53 | ); |
54 | 54 | } |
55 | 55 |
|
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 { |
57 | 59 | this.initFlattenModule(); |
58 | | - return this.findInstanceByPrototypeOrToken<T>( |
| 60 | + return this.findInstanceByPrototypeOrToken<TInput, TResult>( |
59 | 61 | typeOrToken, |
60 | 62 | this.contextModuleFixture, |
61 | 63 | ); |
@@ -90,10 +92,10 @@ export class NestApplicationContext implements INestApplicationContext { |
90 | 92 | return !isUndefined((instance as OnModuleInit).onModuleInit); |
91 | 93 | } |
92 | 94 |
|
93 | | - private findInstanceByPrototypeOrToken<T>( |
94 | | - metatypeOrToken: Type<T> | string | symbol, |
| 95 | + private findInstanceByPrototypeOrToken<TInput = any, TResult = TInput>( |
| 96 | + metatypeOrToken: Type<TInput> | string | symbol, |
95 | 97 | contextModule, |
96 | | - ): T { |
| 98 | + ): TResult { |
97 | 99 | const dependencies = new Map([ |
98 | 100 | ...contextModule.components, |
99 | 101 | ...contextModule.routes, |
|
0 commit comments