From d03b2b9ad5df3aecbead6a5ba573e0b1015d7486 Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Tue, 27 Jun 2017 17:57:35 -0400 Subject: [PATCH] [jquery] Change Promise2 to extend from Promise3. --- types/jquery/index.d.ts | 295 +---------------------------------- types/jquery/jquery-tests.ts | 41 ++--- 2 files changed, 18 insertions(+), 318 deletions(-) diff --git a/types/jquery/index.d.ts b/types/jquery/index.d.ts index e92560017d..862cd57e4a 100644 --- a/types/jquery/index.d.ts +++ b/types/jquery/index.d.ts @@ -4591,10 +4591,6 @@ declare namespace JQuery { (t: T, u: U, v: V): void; } - interface Callback2 { - (t: T, u: U): void; - } - interface Callback { (...args: T[]): void; } @@ -5059,294 +5055,9 @@ declare namespace JQuery { * @see {@link http://api.jquery.com/Types/#Promise} */ interface Promise2 { - /** - * Add handlers to be called when the Deferred object is either resolved or rejected. - * - * @param alwaysCallback A function, or array of functions, that is called when the Deferred is resolved or rejected. - * @param alwaysCallbacks Optional additional functions, or arrays of functions, that are called when the Deferred is resolved or rejected. - * @see {@link https://api.jquery.com/deferred.always/} - * @since 1.6 - */ - always(alwaysCallback: TypeOrArray>, - ...alwaysCallbacks: Array>>): this; - /** - * Add handlers to be called when the Deferred object is resolved. - * - * @param doneCallback A function, or array of functions, that are called when the Deferred is resolved. - * @param doneCallbacks Optional additional functions, or arrays of functions, that are called when the Deferred is resolved. - * @see {@link https://api.jquery.com/deferred.done/} - * @since 1.5 - */ - done(doneCallback: TypeOrArray>, - ...doneCallbacks: Array>>): this; - /** - * Add handlers to be called when the Deferred object is rejected. - * - * @param failCallback A function, or array of functions, that are called when the Deferred is rejected. - * @param failCallbacks Optional additional functions, or arrays of functions, that are called when the Deferred is rejected. - * @see {@link https://api.jquery.com/deferred.fail/} - * @since 1.5 - */ - fail(failCallback: TypeOrArray>, - ...failCallbacks: Array>>): this; - /** - * Add handlers to be called when the Deferred object generates progress notifications. - * - * @param progressCallback A function, or array of functions, to be called when the Deferred generates progress notifications. - * @param progressCallbacks Optional additional functions, or arrays of functions, to be called when the Deferred generates - * progress notifications. - * @see {@link https://api.jquery.com/deferred.progress/} - * @since 1.7 - */ - progress(progressCallback: TypeOrArray>, - ...progressCallbacks: Array>>): this; - /** - * Return a Deferred's Promise object. - * - * @param target Object onto which the promise methods have to be attached - * @see {@link https://api.jquery.com/deferred.promise/} - * @since 1.5 - */ - promise(target: TTarget): this & TTarget; - /** - * Return a Deferred's Promise object. - * - * @see {@link https://api.jquery.com/deferred.promise/} - * @since 1.5 - */ - promise(): this; - /** - * Determine the current state of a Deferred object. - * - * @see {@link https://api.jquery.com/deferred.state/} - * @since 1.7 - */ - state(): 'pending' | 'resolved' | 'rejected'; - - /** - * Add handlers to be called when the Deferred object is rejected. - * - * @param failFilter A function that is called when the Deferred is rejected. - * @see {@link https://api.jquery.com/deferred.catch/} - * @since 3.0 - */ - catch - (failFilter: (t: TJ, u: UJ) => Promise2 | Thenable | AR): Promise2; - - /** - * Utility method to filter and/or chain Deferreds. - * - * @param doneFilter An optional function that is called when the Deferred is resolved. - * @param failFilter An optional function that is called when the Deferred is rejected. - * @param progressFilter An optional function that is called when progress notifications are sent to the Deferred. - * @see {@link https://api.jquery.com/deferred.pipe/} - * @since 1.6 - * @since 1.7 - * @deprecated 1.8 - */ - pipe - (doneFilter: (t: TR, u: UR) => Promise2 | Thenable | AR1, - failFilter: (t: TJ, u: UJ) => Promise2 | Thenable | AR2, - progressFilter: (t: TN, u: UN) => Promise2 | Thenable | AN3): Promise2; - /** - * Utility method to filter and/or chain Deferreds. - * - * @param doneFilter An optional function that is called when the Deferred is resolved. - * @param failFilter An optional function that is called when the Deferred is rejected. - * @param progressFilter An optional function that is called when progress notifications are sent to the Deferred. - * @see {@link https://api.jquery.com/deferred.pipe/} - * @since 1.6 - * @since 1.7 - * @deprecated 1.8 - */ - pipe - (doneFilter: null, - failFilter: (t: TJ, u: UJ) => Promise2 | Thenable | AR1, - progressFilter: (t: TN, u: UN) => Promise2 | Thenable | AN1): Promise2; - /** - * Utility method to filter and/or chain Deferreds. - * - * @param doneFilter An optional function that is called when the Deferred is resolved. - * @param failFilter An optional function that is called when the Deferred is rejected. - * @param progressFilter An optional function that is called when progress notifications are sent to the Deferred. - * @see {@link https://api.jquery.com/deferred.pipe/} - * @since 1.6 - * @since 1.7 - * @deprecated 1.8 - */ - pipe - (doneFilter: (t: TR, u: UR) => Promise2 | Thenable | AR1, - failFilter: null, - progressFilter: (t: TN, u: UN) => Promise2 | Thenable | AN1): Promise2; - /** - * Utility method to filter and/or chain Deferreds. - * - * @param doneFilter An optional function that is called when the Deferred is resolved. - * @param failFilter An optional function that is called when the Deferred is rejected. - * @param progressFilter An optional function that is called when progress notifications are sent to the Deferred. - * @see {@link https://api.jquery.com/deferred.pipe/} - * @since 1.6 - * @since 1.7 - * @deprecated 1.8 - */ - pipe - (doneFilter: null, - failFilter: null, - progressFilter: (t: TN, u: UN) => Promise2 | Thenable | AN): Promise2; - /** - * Utility method to filter and/or chain Deferreds. - * - * @param doneFilter An optional function that is called when the Deferred is resolved. - * @param failFilter An optional function that is called when the Deferred is rejected. - * @see {@link https://api.jquery.com/deferred.pipe/} - * @since 1.6 - * @since 1.7 - * @deprecated 1.8 - */ - pipe - (doneFilter: (t: TR, u: UR) => Promise2 | Thenable | AR1, - failFilter: (t: TJ, u: UJ) => Promise2 | Thenable | AR2, - progressFilter?: null): Promise2; - /** - * Utility method to filter and/or chain Deferreds. - * - * @param doneFilter An optional function that is called when the Deferred is resolved. - * @param failFilter An optional function that is called when the Deferred is rejected. - * @see {@link https://api.jquery.com/deferred.pipe/} - * @since 1.6 - * @since 1.7 - * @deprecated 1.8 - */ - pipe - (doneFilter: null, - failFilter: (t: TJ, u: UJ) => Promise2 | Thenable | AR, - progressFilter?: null): Promise2; - /** - * Utility method to filter and/or chain Deferreds. - * - * @param doneFilter An optional function that is called when the Deferred is resolved. - * @see {@link https://api.jquery.com/deferred.pipe/} - * @since 1.6 - * @since 1.7 - * @deprecated 1.8 - */ - pipe - (doneFilter: ((t: TR, u: UR) => Promise2 | Thenable | AR) | null, - failFilter?: null, - progressFilter?: null): Promise2; - - /** - * Add handlers to be called when the Deferred object is resolved, rejected, or still in progress. - * - * @param doneFilter A function that is called when the Deferred is resolved. - * @param failFilter An optional function that is called when the Deferred is rejected. - * @param progressFilter An optional function that is called when progress notifications are sent to the Deferred. - * @see {@link https://api.jquery.com/deferred.then/} - * @since 1.8 - */ - then - (doneFilter: (t: TR, u: UR) => Promise2 | Thenable | AR1, - failFilter: (t: TJ, u: UJ) => Promise2 | Thenable | AR2, - progressFilter: (t: TN, u: UN) => Promise2 | Thenable | AN3): Promise2; - /** - * Add handlers to be called when the Deferred object is resolved, rejected, or still in progress. - * - * @param doneFilter A function that is called when the Deferred is resolved. - * @param failFilter An optional function that is called when the Deferred is rejected. - * @param progressFilter An optional function that is called when progress notifications are sent to the Deferred. - * @see {@link https://api.jquery.com/deferred.then/} - * @since 1.8 - */ - then - (doneFilter: null, - failFilter: (t: TJ, u: UJ) => Promise2 | Thenable | AR1, - progressFilter: (t: TN, u: UN) => Promise2 | Thenable | AN1): Promise2; - /** - * Add handlers to be called when the Deferred object is resolved, rejected, or still in progress. - * - * @param doneFilter A function that is called when the Deferred is resolved. - * @param failFilter An optional function that is called when the Deferred is rejected. - * @param progressFilter An optional function that is called when progress notifications are sent to the Deferred. - * @see {@link https://api.jquery.com/deferred.then/} - * @since 1.8 - */ - then - (doneFilter: (t: TR, u: UR) => Promise2 | Thenable | AR1, - failFilter: null, - progressFilter: (t: TN, u: UN) => Promise2 | Thenable | AN1): Promise2; - /** - * Add handlers to be called when the Deferred object is resolved, rejected, or still in progress. - * - * @param doneFilter A function that is called when the Deferred is resolved. - * @param failFilter An optional function that is called when the Deferred is rejected. - * @param progressFilter An optional function that is called when progress notifications are sent to the Deferred. - * @see {@link https://api.jquery.com/deferred.then/} - * @since 1.8 - */ - then - (doneFilter: null, - failFilter: null, - progressFilter: (t: TN, u: UN) => Promise2 | Thenable | AN): Promise2; - /** - * Add handlers to be called when the Deferred object is resolved, rejected, or still in progress. - * - * @param doneFilter A function that is called when the Deferred is resolved. - * @param failFilter An optional function that is called when the Deferred is rejected. - * @see {@link https://api.jquery.com/deferred.then/} - * @since 1.8 - */ - then - (doneFilter: (t: TR, u: UR) => Promise2 | Thenable | AR1, - failFilter: (t: TJ, u: UJ) => Promise2 | Thenable | AR2, - progressFilter?: null): Promise2; - /** - * Add handlers to be called when the Deferred object is resolved, rejected, or still in progress. - * - * @param doneFilter A function that is called when the Deferred is resolved. - * @param failFilter An optional function that is called when the Deferred is rejected. - * @see {@link https://api.jquery.com/deferred.then/} - * @since 1.8 - */ - then - (doneFilter: null, - failFilter: (t: TJ, u: UJ) => Promise2 | Thenable | AR, - progressFilter?: null): Promise2; - /** - * Add handlers to be called when the Deferred object is resolved, rejected, or still in progress. - * - * @param doneFilter A function that is called when the Deferred is resolved. - * @see {@link https://api.jquery.com/deferred.then/} - * @since 1.8 - */ - then - (doneFilter: ((t: TR, u: UR) => Promise2 | Thenable | AR) | null, - failFilter?: null, - progressFilter?: null): Promise2; - } + UR, UJ, UN> extends Promise3 { } /** * This object provides a subset of the methods of the Deferred object (then, done, fail, always, diff --git a/types/jquery/jquery-tests.ts b/types/jquery/jquery-tests.ts index 93a147bbfe..7347a8a415 100644 --- a/types/jquery/jquery-tests.ts +++ b/types/jquery/jquery-tests.ts @@ -4579,9 +4579,9 @@ function JQueryStatic() { } function Promise2() { - const t = $.Deferred() as JQuery.Promise2; - const u = $.Deferred() as JQuery.Promise2; - const v = $.Deferred() as JQuery.Promise2; + const t = $.Deferred() as JQuery.Promise2; + const u = $.Deferred() as JQuery.Promise2; + const v = $.Deferred() as JQuery.Promise2; // 3 parameters { @@ -5364,11 +5364,6 @@ function jqXHR() { errorThrown; }); } - - function then_returnType() { - // $ExpectType Promise3, never, never, ErrorTextStatus, never, never, string, never> - $.ajax('/echo/json').then(() => { }); - } } function Promise3() { @@ -5800,7 +5795,7 @@ function Promise2(p: JQuery.Promise2 { a; // $ExpectType Error b; // $ExpectType string - }); + }, null); p.then((a, b) => { a; // $ExpectType string @@ -5808,11 +5803,6 @@ function Promise2(p: JQuery.Promise2 { a; // $ExpectType Error b; // $ExpectType string - }, null); - - p.then(null, (a, b) => { - a; // $ExpectType Error - b; // $ExpectType string }); p.then(null, (a, b) => { @@ -5820,26 +5810,25 @@ function Promise2(p: JQuery.Promise2 { - a; // $ExpectType string - b; // $ExpectType JQuery + p.then(null, (a, b) => { + a; // $ExpectType Error + b; // $ExpectType string }); - p.then((a, b) => { - a; // $ExpectType string - b; // $ExpectType JQuery - }, null); - p.then((a, b) => { a; // $ExpectType string b; // $ExpectType JQuery }, null, null); - p.then(null); + p.then((a, b) => { + a; // $ExpectType string + b; // $ExpectType JQuery + }, null); - p.then(null, null); - - p.then(null, null, null); + p.then((a, b) => { + a; // $ExpectType string + b; // $ExpectType JQuery + }); function doneFilter() { p.then(() => {