Skip to content

Commit 9dd6cf7

Browse files
csvnchristopherthielen
authored andcommitted
fix($InjectorLike) Optional generic type support (#3068)
When working with Typescript, you currently need to do something like this to set type correctly: ```typescript $urlRouterProvider.otherwise(($injector) => { let myService: MyService = $injector.get('myService'); myService.doSomething(); }); ``` With this change, you could instead write the above like this: ```typescript $urlRouterProvider.otherwise(($injector) => { $injector .get<MyService>('myService') .doSomething(); }); ```
1 parent 2e6c323 commit 9dd6cf7

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/common/coreservices.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export interface $QLike {
4141

4242
export interface $InjectorLike {
4343
get(token: any): any;
44+
get<T>(token: any): T;
4445
has(token: any): boolean;
4546
invoke(fn: IInjectable, context?: any, locals?: Obj): any;
4647
annotate(fn: IInjectable, strictDi?: boolean): any[];
@@ -81,4 +82,4 @@ export interface TemplateServices {
8182
}
8283

8384

84-
export {services};
85+
export {services};

src/common/interface.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export interface UIInjector {
3636
* @return the Dependency Injection value that matches the token
3737
*/
3838
get(token: any): any;
39+
get<T>(token: any): T;
3940

4041
/**
4142
* Asynchronously gets a value from the injector
@@ -58,6 +59,7 @@ export interface UIInjector {
5859
* @return a Promise for the Dependency Injection value that matches the token
5960
*/
6061
getAsync(token: any): Promise<any>;
62+
getAsync<T>(token: any): Promise<T>;
6163

6264
/**
6365
* Gets a value from the native injector
@@ -73,4 +75,5 @@ export interface UIInjector {
7375
* @return the Dependency Injection value that matches the token
7476
*/
7577
getNative(token: any): any;
78+
getNative<T>(token: any): T;
7679
}

0 commit comments

Comments
 (0)