From d158d782e9dfc42ae7373d11abfa98507702ddb5 Mon Sep 17 00:00:00 2001 From: Quentin Bouygues Date: Fri, 14 Dec 2018 17:18:57 +0100 Subject: [PATCH] Test IDirective changes, cascade generics from IModule's directive function --- types/angular/angular-tests.ts | 44 ++++++++++++++++++++++++++++------ types/angular/index.d.ts | 9 +++---- 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/types/angular/angular-tests.ts b/types/angular/angular-tests.ts index 44f8539af2..6d3886edc6 100644 --- a/types/angular/angular-tests.ts +++ b/types/angular/angular-tests.ts @@ -1502,16 +1502,46 @@ interface MyScope extends ng.IScope { foo: string; } -const directiveCompileFnWithGeneric: ng.IDirectiveCompileFn = ( - templateElement: JQLite, - templateAttributes: ng.IAttributes, - transclude: ng.ITranscludeFunction - ): ng.IDirectiveLinkFn => { +interface MyElement extends JQLite { + foo: string; +} + +interface MyAttributes extends ng.IAttributes { + foo: string; +} +interface MyController extends ng.INgModelController { + foo: string; +} + +const directiveCompileFnWithGeneric: ng.IDirectiveCompileFn = ( + templateElement: MyElement, + templateAttributes: MyAttributes, + transclude: ng.ITranscludeFunction, + ): ng.IDirectiveLinkFn => { return ( scope: MyScope, - instanceElement: JQLite, - instanceAttributes: ng.IAttributes + instanceElement: MyElement, + instanceAttributes: MyAttributes, + controller: MyController, ) => { return null; }; }; + +const directiveFactoryWithGeneric: ng.IDirectiveFactory = ( + templateElement: MyElement, + templateAttributes: MyAttributes, + transclude: ng.ITranscludeFunction, +): ng.IDirective => { + return { + link: ($scope: MyScope, templateElement: MyElement, templateAttributes: MyAttributes, controller: MyController) => {return; } + }; +}; + +const directiveFactoryWithGeneric2: ng.IDirectiveFactory = ( + templateElement: MyElement, + templateAttributes: MyAttributes, + transclude: ng.ITranscludeFunction, +): ng.IDirectiveLinkFn => { + return ($scope: MyScope, templateElement: MyElement, templateAttributes: MyAttributes, controller: MyController) => {return; }; +}; diff --git a/types/angular/index.d.ts b/types/angular/index.d.ts index 150d63a08d..4a8b26fba9 100644 --- a/types/angular/index.d.ts +++ b/types/angular/index.d.ts @@ -240,8 +240,9 @@ 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. * @@ -1346,8 +1347,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; component(object: {[componentName: string]: IComponentOptions}): ICompileProvider;