mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 20:40:20 +00:00
[jquery] Fixed signatures on Ajax-related methods on JQuery.
Added tests for Ajax-related methods on JQuery.
This commit is contained in:
Vendored
+6
-6
@@ -129,7 +129,7 @@ interface JQuery<TElement extends Node = HTMLElement> {
|
||||
* @see {@link https://api.jquery.com/ajaxComplete/}
|
||||
* @since 1.0
|
||||
*/
|
||||
ajaxComplete(handler: (this: Document, event: JQuery.Event<TElement>, jqXHR: JQuery.jqXHR, ajaxOptions: JQuery.AjaxSettings) => void | false): this;
|
||||
ajaxComplete(handler: (this: Document, event: JQuery.Event<Document>, jqXHR: JQuery.jqXHR, ajaxOptions: JQuery.AjaxSettings) => void | false): this;
|
||||
/**
|
||||
* Register a handler to be called when Ajax requests complete with an error. This is an Ajax Event.
|
||||
*
|
||||
@@ -137,7 +137,7 @@ interface JQuery<TElement extends Node = HTMLElement> {
|
||||
* @see {@link https://api.jquery.com/ajaxError/}
|
||||
* @since 1.0
|
||||
*/
|
||||
ajaxError(handler: (this: Document, event: JQuery.Event<TElement>, jqXHR: JQuery.jqXHR, ajaxSettings: JQuery.AjaxSettings, thrownError: string) => void | false): this;
|
||||
ajaxError(handler: (this: Document, event: JQuery.Event<Document>, jqXHR: JQuery.jqXHR, ajaxSettings: JQuery.AjaxSettings, thrownError: string) => void | false): this;
|
||||
/**
|
||||
* Attach a function to be executed before an Ajax request is sent. This is an Ajax Event.
|
||||
*
|
||||
@@ -145,7 +145,7 @@ interface JQuery<TElement extends Node = HTMLElement> {
|
||||
* @see {@link https://api.jquery.com/ajaxSend/}
|
||||
* @since 1.0
|
||||
*/
|
||||
ajaxSend(handler: (this: Document, event: JQuery.Event<TElement>, jqXHR: JQuery.jqXHR, ajaxOptions: JQuery.AjaxSettings) => void | false): this;
|
||||
ajaxSend(handler: (this: Document, event: JQuery.Event<Document>, jqXHR: JQuery.jqXHR, ajaxOptions: JQuery.AjaxSettings) => void | false): this;
|
||||
/**
|
||||
* Register a handler to be called when the first Ajax request begins. This is an Ajax Event.
|
||||
*
|
||||
@@ -169,7 +169,7 @@ interface JQuery<TElement extends Node = HTMLElement> {
|
||||
* @see {@link https://api.jquery.com/ajaxSuccess/}
|
||||
* @since 1.0
|
||||
*/
|
||||
ajaxSuccess(handler: (this: Document, event: JQuery.Event<TElement>, jqXHR: JQuery.jqXHR, ajaxOptions: JQuery.AjaxSettings, data: JQuery.PlainObject) => void | false): this;
|
||||
ajaxSuccess(handler: (this: Document, event: JQuery.Event<Document>, jqXHR: JQuery.jqXHR, ajaxOptions: JQuery.AjaxSettings, data: JQuery.PlainObject) => void | false): this;
|
||||
/**
|
||||
* Perform a custom animation of a set of CSS properties.
|
||||
*
|
||||
@@ -1147,7 +1147,7 @@ interface JQuery<TElement extends Node = HTMLElement> {
|
||||
*/
|
||||
load(url: string,
|
||||
data: string | JQuery.PlainObject,
|
||||
complete: (this: TElement, responseText: string, textStatus: JQuery.Ajax.SuccessTextStatus, jqXHR: JQuery.jqXHR) => void): this;
|
||||
complete: (this: TElement, responseText: string, textStatus: JQuery.Ajax.TextStatus, jqXHR: JQuery.jqXHR) => void): this;
|
||||
/**
|
||||
* Load data from the server and place the returned HTML into the matched element.
|
||||
*
|
||||
@@ -1158,7 +1158,7 @@ interface JQuery<TElement extends Node = HTMLElement> {
|
||||
* @since 1.0
|
||||
*/
|
||||
load(url: string,
|
||||
complete_data?: ((this: TElement, responseText: string, textStatus: JQuery.Ajax.SuccessTextStatus, jqXHR: JQuery.jqXHR) => void) | string | JQuery.PlainObject): this;
|
||||
complete_data?: ((this: TElement, responseText: string, textStatus: JQuery.Ajax.TextStatus, jqXHR: JQuery.jqXHR) => void) | string | JQuery.PlainObject): this;
|
||||
/**
|
||||
* Pass each element in the current matched set through a function, producing a new jQuery object
|
||||
* containing the return values.
|
||||
|
||||
@@ -9,6 +9,140 @@ function JQuery() {
|
||||
$('div')[0] === new HTMLElement();
|
||||
}
|
||||
|
||||
function ajax() {
|
||||
function ajaxComplete() {
|
||||
// $ExpectType JQuery<HTMLElement>
|
||||
$(document).ajaxComplete(function(event, jqXHR, ajaxOptions) {
|
||||
// $ExpectType Document
|
||||
this;
|
||||
// $ExpectType Event<Document, null>
|
||||
event;
|
||||
// $ExpectType jqXHR<any>
|
||||
jqXHR;
|
||||
// $ExpectType AjaxSettings<any>
|
||||
ajaxOptions;
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
function ajaxError() {
|
||||
// $ExpectType JQuery<HTMLElement>
|
||||
$(document).ajaxError(function(event, jqXHR, ajaxSettings, thrownError) {
|
||||
// $ExpectType Document
|
||||
this;
|
||||
// $ExpectType Event<Document, null>
|
||||
event;
|
||||
// $ExpectType jqXHR<any>
|
||||
jqXHR;
|
||||
// $ExpectType AjaxSettings<any>
|
||||
ajaxSettings;
|
||||
// $ExpectType string
|
||||
thrownError;
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
function ajaxSend() {
|
||||
// $ExpectType JQuery<HTMLElement>
|
||||
$(document).ajaxSend(function(event, jqXHR, ajaxOptions) {
|
||||
// $ExpectType Document
|
||||
this;
|
||||
// $ExpectType Event<Document, null>
|
||||
event;
|
||||
// $ExpectType jqXHR<any>
|
||||
jqXHR;
|
||||
// $ExpectType AjaxSettings<any>
|
||||
ajaxOptions;
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
function ajaxStart() {
|
||||
// $ExpectType JQuery<HTMLElement>
|
||||
$(document).ajaxStart(function() {
|
||||
// $ExpectType Document
|
||||
this;
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
function ajaxStop() {
|
||||
// $ExpectType JQuery<HTMLElement>
|
||||
$(document).ajaxStop(function() {
|
||||
// $ExpectType Document
|
||||
this;
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
function ajaxSuccess() {
|
||||
// $ExpectType JQuery<HTMLElement>
|
||||
$(document).ajaxSuccess(function(event, jqXHR, ajaxOptions, data) {
|
||||
// $ExpectType Document
|
||||
this;
|
||||
// $ExpectType Event<Document, null>
|
||||
event;
|
||||
// $ExpectType jqXHR<any>
|
||||
jqXHR;
|
||||
// $ExpectType AjaxSettings<any>
|
||||
ajaxOptions;
|
||||
// $ExpectType PlainObject<any>
|
||||
data;
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
function load() {
|
||||
// $ExpectType JQuery<HTMLElement>
|
||||
$('#result').load('/echo/html/', 'data', function(responseText, textStatus, jqXHR) {
|
||||
// $ExpectType HTMLElement
|
||||
this;
|
||||
// $ExpectType string
|
||||
responseText;
|
||||
// $ExpectType TextStatus
|
||||
textStatus;
|
||||
// $ExpectType jqXHR<any>
|
||||
jqXHR;
|
||||
});
|
||||
|
||||
// $ExpectType JQuery<HTMLElement>
|
||||
$('#result').load('/echo/html/', { data: 'data' }, function(responseText, textStatus, jqXHR) {
|
||||
// $ExpectType HTMLElement
|
||||
this;
|
||||
// $ExpectType string
|
||||
responseText;
|
||||
// $ExpectType TextStatus
|
||||
textStatus;
|
||||
// $ExpectType jqXHR<any>
|
||||
jqXHR;
|
||||
});
|
||||
|
||||
// $ExpectType JQuery<HTMLElement>
|
||||
$('#result').load('/echo/html/', function(responseText, textStatus, jqXHR) {
|
||||
// $ExpectType HTMLElement
|
||||
this;
|
||||
// $ExpectType string
|
||||
responseText;
|
||||
// $ExpectType TextStatus
|
||||
textStatus;
|
||||
// $ExpectType jqXHR<any>
|
||||
jqXHR;
|
||||
});
|
||||
|
||||
// $ExpectType JQuery<HTMLElement>
|
||||
$('#result').load('/echo/html/', 'data');
|
||||
|
||||
// $ExpectType JQuery<HTMLElement>
|
||||
$('#result').load('/echo/html/', { data: 'data' });
|
||||
}
|
||||
}
|
||||
|
||||
function on() {
|
||||
function false_handler_shorthand() {
|
||||
$().on('events', false);
|
||||
@@ -184,7 +318,9 @@ function jqXHR() {
|
||||
$.ajax('/echo').fail((jqXHR, textStatus, errorThrown) => {
|
||||
// $ExpectType jqXHR<any>
|
||||
jqXHR;
|
||||
// $ExpectType "abort" | "timeout" | "error" | "parsererror" | null
|
||||
// This test is flaky
|
||||
// Should be 'ErrorTextStatus | null' and should be able to handle it out of order
|
||||
// $ExpectType "timeout" | "error" | "abort" | "parsererror" | null
|
||||
textStatus;
|
||||
// $ExpectType string
|
||||
errorThrown;
|
||||
|
||||
Reference in New Issue
Block a user