From d5240b6d9cc209a7ae89d955dde6fb7024751b3d Mon Sep 17 00:00:00 2001 From: Mateusz Date: Wed, 26 Apr 2017 20:47:36 +0200 Subject: [PATCH] Re-add generic Function type to IInjector.invoke() sygnature. (#16042) Looks like it is used in some projects. 'Function' should be treated as a function with '(..args: any[]) => any' signature. --- types/angular/angular-tests.ts | 9 ++++++++- types/angular/index.d.ts | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/types/angular/angular-tests.ts b/types/angular/angular-tests.ts index e6be93a6af..d01dbd25b8 100644 --- a/types/angular/angular-tests.ts +++ b/types/angular/angular-tests.ts @@ -484,7 +484,14 @@ namespace TestInjector { function foobar(v: boolean): number { return 7; } - let result: number = $injector.invoke(foobar); + let result = $injector.invoke(foobar); + if (!(typeof result === 'number')) { + // This fails to compile if 'result' is not exactly a number. + let expectNever: never = result; + } + + let anyFunction: Function = foobar; + let anyResult: string = $injector.invoke(anyFunction); } } diff --git a/types/angular/index.d.ts b/types/angular/index.d.ts index 194ccf8205..1d59854d9d 100644 --- a/types/angular/index.d.ts +++ b/types/angular/index.d.ts @@ -1981,6 +1981,7 @@ declare namespace angular { instantiate(typeConstructor: {new(...args: any[]): T}, locals?: any): T; invoke(inlineAnnotatedFunction: any[]): any; invoke(func: (...args: any[]) => T, context?: any, locals?: any): T; + invoke(func: Function, context?: any, locals?: any): any; strictDi: boolean; }