Skip to content

Commit 661fc86

Browse files
committed
JQuery: make JQueryXHR.then method generic.
1 parent ba4c4fc commit 661fc86

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

jquery/jquery-tests.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ function test_ajax() {
199199
console.log(jqXHR, textStatus, errorThrown);
200200
});
201201

202+
// generic then method
203+
var p: JQueryPromise<number> = $.ajax({ url: "test.js" })
204+
.then(() => "Hello")
205+
.then((x) => x.length);
206+
202207
// jqXHR object
203208
var jqXHR = $.ajax({
204209
url: "test.js"

jquery/jquery.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ interface JQueryXHR extends XMLHttpRequest, JQueryPromise<any> {
180180
/**
181181
* Incorporates the functionality of the .done() and .fail() methods, allowing (as of jQuery 1.8) the underlying Promise to be manipulated. Refer to deferred.then() for implementation details.
182182
*/
183-
then(doneCallback: (data: any, textStatus: string, jqXHR: JQueryXHR) => void, failCallback?: (jqXHR: JQueryXHR, textStatus: string, errorThrown: any) => void): JQueryPromise<any>;
183+
then<R>(doneCallback: (data: any, textStatus: string, jqXHR: JQueryXHR) => R, failCallback?: (jqXHR: JQueryXHR, textStatus: string, errorThrown: any) => void): JQueryPromise<R>;
184184
/**
185185
* Property containing the parsed response if the response Content-Type is json
186186
*/

0 commit comments

Comments
 (0)