From 30b9603742856c86b1424d3bd77da4b140ee89b4 Mon Sep 17 00:00:00 2001 From: Mateusz Greszta Date: Tue, 18 Apr 2017 16:59:54 +0200 Subject: [PATCH] Improve types of 'instantiate' and 'invoke' of IInjectorService. The result is inferred form the argument, which removes the need of any cast. --- types/angular/angular-tests.ts | 16 ++++++++++++++++ types/angular/index.d.ts | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/types/angular/angular-tests.ts b/types/angular/angular-tests.ts index 53fd245f1d..e6be93a6af 100644 --- a/types/angular/angular-tests.ts +++ b/types/angular/angular-tests.ts @@ -470,6 +470,22 @@ namespace TestInjector { $injector.annotate(() => {}); $injector.annotate(() => {}, true); + + // $injector.instantiate + { + class Foobar { + constructor($q) {} + } + let result: Foobar = $injector.instantiate(Foobar); + } + + // $injector.invoke + { + function foobar(v: boolean): number { + return 7; + } + let result: number = $injector.invoke(foobar); + } } // Promise signature tests diff --git a/types/angular/index.d.ts b/types/angular/index.d.ts index 727944fbb1..194ccf8205 100644 --- a/types/angular/index.d.ts +++ b/types/angular/index.d.ts @@ -1978,9 +1978,9 @@ declare namespace angular { get(name: '$window'): IWindowService; get(name: '$xhrFactory'): IXhrFactory; has(name: string): boolean; - instantiate(typeConstructor: Function, locals?: any): T; + instantiate(typeConstructor: {new(...args: any[]): T}, locals?: any): T; invoke(inlineAnnotatedFunction: any[]): any; - invoke(func: Function, context?: any, locals?: any): any; + invoke(func: (...args: any[]) => T, context?: any, locals?: any): T; strictDi: boolean; }