diff --git a/types/jquery/index.d.ts b/types/jquery/index.d.ts index 8422f3ec5c..be4b2f2346 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. * @@ -4531,6 +4546,19 @@ interface JQuery extends Iterable on(events: string, 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. * @@ -4543,6 +4571,18 @@ 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. * @@ -4554,6 +4594,16 @@ interface JQuery extends Iterable */ on(events: string, 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 handler A function to execute when the event is triggered. + * @see {@link https://api.jquery.com/on/} + * @since 1.7 + */ + on(events: string, + 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 5d6aaf0680..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 @@ -3701,6 +3733,38 @@ function JQuery() { event; }); + // $ExpectType JQuery + $('table').on('myEvent', function(event: JQueryEventObject) { + // $ExpectType HTMLElement + this; + // $ExpectType JQueryEventObject + event; + }); + + // $ExpectType JQuery + $('table').on('myEvent', function(event: JQueryInputEventObject) { + // $ExpectType HTMLElement + this; + // $ExpectType JQueryInputEventObject + event; + }); + + // $ExpectType JQuery + $('table').on('myEvent', function(event: JQueryMouseEventObject) { + // $ExpectType HTMLElement + this; + // $ExpectType JQueryMouseEventObject + event; + }); + + // $ExpectType JQuery + $('table').on('myEvent', function(event: JQueryKeyEventObject) { + // $ExpectType HTMLElement + this; + // $ExpectType JQueryKeyEventObject + event; + }); + // $ExpectType JQuery $('table').on('myEvent', function(this: I1, event) { // $ExpectType I1