From 7007542e784f343a1d9e9a16ef7991a27f656bd6 Mon Sep 17 00:00:00 2001 From: Holger Jeromin Date: Wed, 16 May 2018 11:29:25 +0200 Subject: [PATCH] adding JQueryEventObject to all on handlers and fix tests --- types/jquery/index.d.ts | 44 ++++++++++++++++++++++++++++++++++-- types/jquery/jquery-tests.ts | 32 ++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/types/jquery/index.d.ts b/types/jquery/index.d.ts index 981993e2d7..9aa6be68a2 100644 --- a/types/jquery/index.d.ts +++ b/types/jquery/index.d.ts @@ -4517,6 +4517,21 @@ interface JQuery extends Iterable selector: JQuery.Selector | null, data: TData, handler: JQuery.EventHandler | JQuery.EventHandlerBase>): this; + /** + * Attach an event handler function for one or more events to the selected elements. + * + * @param events One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin". + * @param selector A selector string to filter the descendants of the selected elements that trigger the event. If the + * selector is null or omitted, the event is always triggered when it reaches the selected element. + * @param data Data to be passed to the handler in event.data when an event is triggered. + * @param handler A function to execute when the event is triggered. + * @see {@link https://api.jquery.com/on/} + * @since 1.7 + */ + on(events: string, + selector: JQuery.Selector | null, + data: TData, + handler: ((event: JQueryEventObject) => void)): this; // tslint:disable-line:unified-signatures /** * Attach an event handler function for one or more events to the selected elements. * @@ -4532,6 +4547,19 @@ interface JQuery extends Iterable selector: JQuery.Selector, handler: JQuery.EventHandler | JQuery.EventHandlerBase> | false): this; /** + * Attach an event handler function for one or more events to the selected elements. + * + * @param events One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin". + * @param selector A selector string to filter the descendants of the selected elements that trigger the event. If the + * selector is null or omitted, the event is always triggered when it reaches the selected element. + * @param handler A function to execute when the event is triggered. + * @see {@link https://api.jquery.com/on/} + * @since 1.7 + */ + on(events: string, + selector: JQuery.Selector, + handler: ((event: JQueryEventObject) => void)): this; // tslint:disable-line:unified-signatures + /** * Attach an event handler function for one or more events to the selected elements. * * @param events One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin". @@ -4543,7 +4571,19 @@ interface JQuery extends Iterable on(events: string, data: TData, handler: JQuery.EventHandler | JQuery.EventHandlerBase>): this; - /** + /** + * Attach an event handler function for one or more events to the selected elements. + * + * @param events One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin". + * @param data Data to be passed to the handler in event.data when an event is triggered. + * @param handler A function to execute when the event is triggered. + * @see {@link https://api.jquery.com/on/} + * @since 1.7 + */ + on(events: string, + data: TData, + handler: ((event: JQueryEventObject) => void)): this; // tslint:disable-line:unified-signatures +/** * Attach an event handler function for one or more events to the selected elements. * * @param events One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin". @@ -4563,7 +4603,7 @@ interface JQuery extends Iterable * @since 1.7 */ on(events: string, - handler: ((event: JQueryEventObject) => void)): this; + handler: ((event: JQueryEventObject) => void)): this; // tslint:disable-line:unified-signatures /** * Attach an event handler function for one or more events to the selected elements. * diff --git a/types/jquery/jquery-tests.ts b/types/jquery/jquery-tests.ts index 5beb6c1a6e..0cceb359b5 100644 --- a/types/jquery/jquery-tests.ts +++ b/types/jquery/jquery-tests.ts @@ -3634,6 +3634,14 @@ function JQuery() { event; }); + // $ExpectType JQuery + $('table').on('myEvent', 'td', 'myData', function(event: JQueryEventObject) { + // $ExpectType HTMLElement + this; + // $ExpectType JQueryEventObject + event; + }); + // $ExpectType JQuery $('table').on('myEvent', 'td', 'myData', function(this: I1, event) { // $ExpectType I1 @@ -3650,6 +3658,14 @@ function JQuery() { event; }); + // $ExpectType JQuery + $('table').on('myEvent', null, 'myData', function(event: JQueryEventObject) { + // $ExpectType HTMLElement + this; + // $ExpectType JQueryEventObject + event; + }); + // $ExpectType JQuery $('table').on('myEvent', null, 'myData', function(this: I1, event) { // $ExpectType I1 @@ -3666,6 +3682,14 @@ function JQuery() { event; }); + // $ExpectType JQuery + $('table').on('myEvent', 'td', function(event: JQueryEventObject) { + // $ExpectType HTMLElement + this; + // $ExpectType JQueryEventObject + event; + }); + // $ExpectType JQuery $('table').on('myEvent', 'td', function(this: I1, event) { // $ExpectType I1 @@ -3685,6 +3709,14 @@ function JQuery() { event; }); + // $ExpectType JQuery + $('table').on('myEvent', 3, function(event: JQueryEventObject) { + // $ExpectType HTMLElement + this; + // $ExpectType JQueryEventObject + event; + }); + // $ExpectType JQuery $('table').on('myEvent', 3, function(this: I1, event) { // $ExpectType I1