diff --git a/types/jquery/index.d.ts b/types/jquery/index.d.ts index 024dcc3ab8..b139de1632 100644 --- a/types/jquery/index.d.ts +++ b/types/jquery/index.d.ts @@ -37,6 +37,8 @@ declare const $: JQueryStatic; // Used by JQuery.Event type _Event = Event; +// Used by JQuery.Promise3 and JQuery.Promise +type _Promise = Promise; interface JQueryStatic { /** @@ -6281,7 +6283,7 @@ declare namespace JQuery { */ interface Promise3 extends PromiseLike { + VR, VJ, VN> extends _Promise, PromiseLike { /** * Add handlers to be called when the Deferred object is either resolved or rejected. * @@ -6685,9 +6687,9 @@ declare namespace JQuery { catch - (failFilter: (t: TJ, u: UJ, v: VJ) => Promise3 Promise3 | Thenable | ARF): Promise3 | Thenable | ARF) | undefined | null): Promise3; } @@ -6709,7 +6711,7 @@ declare namespace JQuery { * * @see {@link http://api.jquery.com/Types/#Promise} */ - interface Promise extends PromiseLike { + interface Promise extends _Promise, PromiseLike { /** * Add handlers to be called when the Deferred object is either resolved or rejected. * diff --git a/types/jquery/jquery-tests.ts b/types/jquery/jquery-tests.ts index d223be9d5c..81ab91d6a3 100644 --- a/types/jquery/jquery-tests.ts +++ b/types/jquery/jquery-tests.ts @@ -6512,6 +6512,8 @@ function _Event() { } function jqXHR() { + const p: JQuery.jqXHR = {} as any; + function always() { // $ExpectType jqXHR $.ajax('/echo/json').always((data_jqXHR, textStatus, jqXHR_errorThrown) => { @@ -6763,6 +6765,10 @@ function jqXHR() { errorThrown; }); } + + function compatibleWithPromise(): Promise { + return p; + } } function Promise3() { @@ -7145,6 +7151,15 @@ function Promise3() { $.ajax('/echo/json').catch(() => { return $.ajax('/echo/json'); }); + + // $ExpectType Promise3 + $.ajax('/echo/json').catch(undefined); + + // $ExpectType Promise3 + $.ajax('/echo/json').catch(null); + + // $ExpectType Promise3 + $.ajax('/echo/json').catch(); } // As argument to PromiseLike parameter @@ -7157,6 +7172,10 @@ function Promise3() { async function testAsync(p: JQuery.Promise3): Promise { return await p; } + + function compatibleWithPromise(): Promise { + return p; + } } function Promise2(p: JQuery.Promise2) { @@ -7292,6 +7311,10 @@ function Promise2(p: JQuery.Promise2): Promise { return await p; } + + function compatibleWithPromise(): Promise { + return p; + } } function _Promise(p: JQuery.Promise) { @@ -7404,4 +7427,8 @@ function _Promise(p: JQuery.Promise) { async function testAsync(p: JQuery.Promise): Promise { return await p; } + + function compatibleWithPromise(): Promise { + return p; + } }