Skip to content
This repository was archived by the owner on Mar 25, 2021. It is now read-only.

Commit 3b81b91

Browse files
committed
fix(di): type enhancement
1 parent 1457d67 commit 3b81b91

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

packages/di/src/injectable-factory.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class InjectableFactory {
2121
this.reflectiveProviders = reflectiveProviders
2222
}
2323

24-
addProvider<T>(provider: Provider<T>): Provider<T> {
24+
addProvider<U, T extends Provider<U>>(provider: T): T {
2525
this.providers.add(provider)
2626
return provider
2727
}
@@ -39,6 +39,9 @@ export class InjectableFactory {
3939
}
4040

4141
resolveProviders() {
42+
if (this.resolved) {
43+
return this
44+
}
4245
if (this.parent && !this.parent.resolved) {
4346
this.parent.resolveProviders()
4447
}

packages/di/src/type.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export interface ValueProvider<T> {
44
/**
55
* An injection token. (Typically an instance of `Type` or `InjectionToken`, but can be `any`).
66
*/
7-
provide: InjectionToken<T>
7+
provide: InjectionToken<T> | Type<T>
88
/**
99
* The value to inject.
1010
*/
@@ -24,7 +24,7 @@ export interface FactoryProvider<T, Deps extends Array<any> = any[]> {
2424
/**
2525
* An injection token. (Typically an instance of `Type` or `InjectionToken`, but can be `any`).
2626
*/
27-
provide: InjectionToken<T>
27+
provide: InjectionToken<T> | Type<T>
2828
/**
2929
* A function to invoke to create a value for this `token`. The function is invoked with
3030
* resolved values of `token`s in the `deps` field.
@@ -50,7 +50,7 @@ export interface ClassProvider<T> {
5050
/**
5151
* An injection token. (Typically an instance of `Type` or `InjectionToken`, but can be `any`).
5252
*/
53-
provide: InjectionToken<T>
53+
provide: Type<T> | InjectionToken<T>
5454
/**
5555
* Class to instantiate for the `token`.
5656
*/
@@ -70,7 +70,7 @@ export interface ExistingProvider<T> {
7070
/**
7171
* An injection token. (Typically an instance of `Type` or `InjectionToken`, but can be `any`).
7272
*/
73-
provide: InjectionToken<T>
73+
provide: InjectionToken<T> | Type<T>
7474
/**
7575
* Existing `token` to return. (equivalent to `injector.get(useExisting)`)
7676
*/

0 commit comments

Comments
 (0)