From bcf764486842479a009b6c479c09f362823b730b Mon Sep 17 00:00:00 2001 From: mtraynham Date: Mon, 6 Nov 2017 11:34:28 -0500 Subject: [PATCH 1/2] Angular - Default IScope generic typings for backwards compatibility --- types/angular/index.d.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/types/angular/index.d.ts b/types/angular/index.d.ts index af2fb37f26..f3b64e2136 100644 --- a/types/angular/index.d.ts +++ b/types/angular/index.d.ts @@ -229,8 +229,8 @@ declare namespace angular { * @param name Name of the directive in camel-case (i.e. ngBind which will match as ng-bind) * @param directiveFactory An injectable directive factory function. */ - directive(name: string, directiveFactory: Injectable>): IModule; - directive(object: {[directiveName: string]: Injectable>}): IModule; + directive(name: string, directiveFactory: Injectable>): IModule; + directive(object: {[directiveName: string]: Injectable>}): IModule; /** * Register a service factory, which will be called to return the service instance. This is short for registering a service where its provider consists of only a $get property, which is the given service factory function. You should use $provide.factory(getFn) if you do not need to configure your service in a provider. * @@ -1249,8 +1249,8 @@ declare namespace angular { } interface ICompileProvider extends IServiceProvider { - directive(name: string, directiveFactory: Injectable>): ICompileProvider; - directive(object: {[directiveName: string]: Injectable>}): ICompileProvider; + directive(name: string, directiveFactory: Injectable>): ICompileProvider; + directive(object: {[directiveName: string]: Injectable>}): ICompileProvider; component(name: string, options: IComponentOptions): ICompileProvider; @@ -1983,12 +1983,12 @@ declare namespace angular { ): void; } - interface IDirectivePrePost { + interface IDirectivePrePost { pre?: IDirectiveLinkFn; post?: IDirectiveLinkFn; } - interface IDirectiveCompileFn { + interface IDirectiveCompileFn { ( templateElement: JQLite, templateAttributes: IAttributes, From 7f84ba072db59996c53aa15f58beb7cc50820a0e Mon Sep 17 00:00:00 2001 From: mtraynham Date: Mon, 6 Nov 2017 11:55:05 -0500 Subject: [PATCH 2/2] Add optional generic typing test for Angular IDirectiveCompileFn --- types/angular/angular-tests.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/types/angular/angular-tests.ts b/types/angular/angular-tests.ts index b4b626b9fa..88a59bdd2a 100644 --- a/types/angular/angular-tests.ts +++ b/types/angular/angular-tests.ts @@ -1324,3 +1324,35 @@ function toPromise(val: T): ng.IPromise { const p: ng.IPromise = null; return p; } + +const directiveCompileFn: ng.IDirectiveCompileFn = ( + templateElement: JQLite, + templateAttributes: ng.IAttributes, + transclude: ng.ITranscludeFunction + ): ng.IDirectiveLinkFn => { + return ( + scope: ng.IScope, + instanceElement: JQLite, + instanceAttributes: ng.IAttributes + ) => { + return null; + }; +}; + +interface MyScope extends ng.IScope { + foo: string; +} + +const directiveCompileFnWithGeneric: ng.IDirectiveCompileFn = ( + templateElement: JQLite, + templateAttributes: ng.IAttributes, + transclude: ng.ITranscludeFunction + ): ng.IDirectiveLinkFn => { + return ( + scope: MyScope, + instanceElement: JQLite, + instanceAttributes: ng.IAttributes + ) => { + return null; + }; +};