Merge pull request #25792 from HolgerJeromin/patch-2

jQuery: Add overload for on() handler for JQueryEventObject
This commit is contained in:
Ron Buckton
2018-05-16 17:00:29 -07:00
committed by GitHub
2 changed files with 114 additions and 0 deletions

View File

@@ -4517,6 +4517,21 @@ interface JQuery<TElement extends Node = HTMLElement> extends Iterable<TElement>
selector: JQuery.Selector | null,
data: TData,
handler: JQuery.EventHandler<TElement, TData> | JQuery.EventHandlerBase<any, JQuery.Event<TElement, TData>>): 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<TData>(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<TElement extends Node = HTMLElement> extends Iterable<TElement>
on(events: string,
selector: JQuery.Selector,
handler: JQuery.EventHandler<TElement> | JQuery.EventHandlerBase<any, JQuery.Event<TElement>> | 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<TElement extends Node = HTMLElement> extends Iterable<TElement>
on<TData>(events: string,
data: TData,
handler: JQuery.EventHandler<TElement, TData> | JQuery.EventHandlerBase<any, JQuery.Event<TElement, TData>>): 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<TData>(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<TElement extends Node = HTMLElement> extends Iterable<TElement>
*/
on(events: string,
handler: JQuery.EventHandler<TElement> | JQuery.EventHandlerBase<any, JQuery.Event<TElement>> | 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.
*

View File

@@ -3634,6 +3634,14 @@ function JQuery() {
event;
});
// $ExpectType JQuery<HTMLElement>
$('table').on('myEvent', 'td', 'myData', function(event: JQueryEventObject) {
// $ExpectType HTMLElement
this;
// $ExpectType JQueryEventObject
event;
});
// $ExpectType JQuery<HTMLElement>
$('table').on('myEvent', 'td', 'myData', function(this: I1, event) {
// $ExpectType I1
@@ -3650,6 +3658,14 @@ function JQuery() {
event;
});
// $ExpectType JQuery<HTMLElement>
$('table').on('myEvent', null, 'myData', function(event: JQueryEventObject) {
// $ExpectType HTMLElement
this;
// $ExpectType JQueryEventObject
event;
});
// $ExpectType JQuery<HTMLElement>
$('table').on('myEvent', null, 'myData', function(this: I1, event) {
// $ExpectType I1
@@ -3666,6 +3682,14 @@ function JQuery() {
event;
});
// $ExpectType JQuery<HTMLElement>
$('table').on('myEvent', 'td', function(event: JQueryEventObject) {
// $ExpectType HTMLElement
this;
// $ExpectType JQueryEventObject
event;
});
// $ExpectType JQuery<HTMLElement>
$('table').on('myEvent', 'td', function(this: I1, event) {
// $ExpectType I1
@@ -3685,6 +3709,14 @@ function JQuery() {
event;
});
// $ExpectType JQuery<HTMLElement>
$('table').on('myEvent', 3, function(event: JQueryEventObject) {
// $ExpectType HTMLElement
this;
// $ExpectType JQueryEventObject
event;
});
// $ExpectType JQuery<HTMLElement>
$('table').on('myEvent', 3, function(this: I1, event) {
// $ExpectType I1
@@ -3701,6 +3733,38 @@ function JQuery() {
event;
});
// $ExpectType JQuery<HTMLElement>
$('table').on('myEvent', function(event: JQueryEventObject) {
// $ExpectType HTMLElement
this;
// $ExpectType JQueryEventObject
event;
});
// $ExpectType JQuery<HTMLElement>
$('table').on('myEvent', function(event: JQueryInputEventObject) {
// $ExpectType HTMLElement
this;
// $ExpectType JQueryInputEventObject
event;
});
// $ExpectType JQuery<HTMLElement>
$('table').on('myEvent', function(event: JQueryMouseEventObject) {
// $ExpectType HTMLElement
this;
// $ExpectType JQueryMouseEventObject
event;
});
// $ExpectType JQuery<HTMLElement>
$('table').on('myEvent', function(event: JQueryKeyEventObject) {
// $ExpectType HTMLElement
this;
// $ExpectType JQueryKeyEventObject
event;
});
// $ExpectType JQuery<HTMLElement>
$('table').on('myEvent', function(this: I1, event) {
// $ExpectType I1