From d2a6dc64c0fd75cdab1eff27d72170f86777a5c2 Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Tue, 27 Jun 2017 17:53:13 -0400 Subject: [PATCH] [jquery] Revise Promise3. --- types/jquery/index.d.ts | 590 +++++++++++++++++++++-------------- types/jquery/jquery-tests.ts | 364 ++++++++++++++------- 2 files changed, 599 insertions(+), 355 deletions(-) diff --git a/types/jquery/index.d.ts b/types/jquery/index.d.ts index 69196b6d00..e92560017d 100644 --- a/types/jquery/index.d.ts +++ b/types/jquery/index.d.ts @@ -4620,6 +4620,19 @@ declare namespace JQuery { interface ProgressCallback extends Callback { } } + // Type parameter guide + // -------------------- + // Each type parameter represents a parameter in one of the three possible callbacks. + // + // The first letter indicates which position the parameter is in. + // + // T = A = 1st position + // U = B = 2nd position + // V = C = 3rd position + // + // The second letter indicates which whether it is a [R]esolve, Re[J]ect, or [N]otify value. + // + // The third letter indicates whether the value is returned in the [D]one filter, [F]ail filter, or [P]rogress filter. /** * This object provides a subset of the methods of the Deferred object (then, done, fail, always, * pipe, progress, state and promise) to prevent users from changing the state of the Deferred. @@ -4628,7 +4641,7 @@ declare namespace JQuery { */ interface Promise3 { + VR, VJ, VN> { /** * Add handlers to be called when the Deferred object is either resolved or rejected. * @@ -4693,6 +4706,335 @@ declare namespace JQuery { */ state(): 'pending' | 'resolved' | 'rejected'; + /** + * 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, v: VR) => Promise3 | Thenable | ARD, + failFilter: (t: TJ, u: UJ, v: VJ) => Promise3 | Thenable | AJF, + progressFilter: (t: TN, u: UN, v: VN) => Promise3 | Thenable | ANP): Promise3; + /** + * 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, v: VJ) => Promise3 | Thenable | AJF, + progressFilter: (t: TN, u: UN, v: VN) => Promise3 | Thenable | ANP): Promise3; + /** + * 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, v: VR) => Promise3 | Thenable | ARD, + failFilter: null, + progressFilter: (t: TN, u: UN, v: VN) => Promise3 | Thenable | ANP): Promise3; + /** + * 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, v: VR) => Promise3 | Thenable | ARD, + failFilter: (t: TJ, u: UJ, v: VJ) => Promise3 | Thenable | AJF, + progressFilter?: null): Promise3; + /** + * 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, v: VR) => Promise3 | Thenable | ARD, + failFilter: (t: TJ, u: UJ, v: VJ) => Promise3 | Thenable | AJF, + progressFilter?: null): Promise3; + /** + * 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, v: VJ) => Promise3 | Thenable | AJF, + progressFilter?: null): Promise3; + /** + * 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, v: VR) => Promise3 | Thenable | ARD, + failFilter?: null, + progressFilter?: null): Promise3; + + /** + * 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, v: VR) => Promise3 | Thenable | ARD, + failFilter: (t: TJ, u: UJ, v: VJ) => Promise3 | Thenable | ARF, + progressFilter: (t: TN, u: UN, v: VN) => Promise3 | Thenable | ANP): Promise3; + /** + * 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, v: VJ) => Promise3 | Thenable | ARF, + progressFilter: (t: TN, u: UN, v: VN) => Promise3 | Thenable | ANP): Promise3; + /** + * 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, v: VR) => Promise3 | Thenable | ARD, + failFilter: null, + progressFilter: (t: TN, u: UN, v: VN) => Promise3 | Thenable | ANP): Promise3; + /** + * 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, v: VN) => Promise3 | Thenable | ANP): Promise3; + /** + * 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, v: VR) => Promise3 | Thenable | ARD, + failFilter: (t: TJ, u: UJ, v: VJ) => Promise3 | Thenable | ARF, + progressFilter?: null): Promise3; + /** + * 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, v: VJ) => Promise3 | Thenable | ARF, + progressFilter?: null): Promise3; + /** + * 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, v: VR) => Promise3 | Thenable | ARD, + failFilter?: null, + progressFilter?: null): Promise3; + /** * Add handlers to be called when the Deferred object is rejected. * @@ -4700,244 +5042,14 @@ declare namespace JQuery { * @see {@link https://api.jquery.com/deferred.catch/} * @since 3.0 */ - catch - (failFilter: (t: TJ, u: UJ, v: VJ) => Promise3 | Thenable | AR): Promise3; - - /** - * 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, v: VR) => Promise3 | Thenable | AR1, - failFilter: (t: TJ, u: UJ, v: VJ) => Promise3 | Thenable | AR2, - progressFilter: (t: TN, u: UN, v: VN) => Promise3 | Thenable | AN3): Promise3; - /** - * 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, v: VJ) => Promise3 | Thenable | AR1, - progressFilter: (t: TN, u: UN, v: VN) => Promise3 | Thenable | AN1): Promise3; - /** - * 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, v: VR) => Promise3 | Thenable | AR1, - failFilter: null, - progressFilter: (t: TN, u: UN, v: VN) => Promise3 | Thenable | AN1): Promise3; - /** - * 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, v: VN) => Promise3 | Thenable | AN): Promise3; - /** - * 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, v: VR) => Promise3 | Thenable | AR1, - failFilter: (t: TJ, u: UJ, v: VJ) => Promise3 | Thenable | AR2, - progressFilter?: null): Promise3; - /** - * 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, v: VJ) => Promise3 | Thenable | AR, - progressFilter?: null): Promise3; - /** - * 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, v: VR) => Promise3 | Thenable | AR) | null, - failFilter?: null, - progressFilter?: null): Promise3; - - /** - * 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, v: VR) => Promise3 | Thenable | AR1, - failFilter: (t: TJ, u: UJ, v: VJ) => Promise3 | Thenable | AR2, - progressFilter: (t: TN, u: UN, v: VN) => Promise3 | Thenable | AN3): Promise3; - /** - * 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, v: VJ) => Promise3 | Thenable | AR1, - progressFilter: (t: TN, u: UN, v: VN) => Promise3 | Thenable | AN1): Promise3; - /** - * 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, v: VR) => Promise3 | Thenable | AR1, - failFilter: null, - progressFilter: (t: TN, u: UN, v: VN) => Promise3 | Thenable | AN1): Promise3; - /** - * 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, v: VN) => Promise3 | Thenable | AN): Promise3; - /** - * 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, v: VR) => Promise3 | Thenable | AR1, - failFilter: (t: TJ, u: UJ, v: VJ) => Promise3 | Thenable | AR2, - progressFilter?: null): Promise3; - /** - * 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, v: VJ) => Promise3 | Thenable | AR, - progressFilter?: null): Promise3; - /** - * 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, v: VR) => Promise3 | Thenable | AR) | null, - failFilter?: null, - progressFilter?: null): Promise3; + catch + (failFilter: (t: TJ, u: UJ, v: VJ) => Promise3 | Thenable | ARF): Promise3; } /** diff --git a/types/jquery/jquery-tests.ts b/types/jquery/jquery-tests.ts index 7b0c521b88..93a147bbfe 100644 --- a/types/jquery/jquery-tests.ts +++ b/types/jquery/jquery-tests.ts @@ -1,3 +1,5 @@ +// tslint:disable:interface-name + function JQuery() { function type_assertion() { const $el = $(document.createElement('canvas')); @@ -4586,40 +4588,25 @@ function JQueryStatic() { const w = $.when(t, u, v); w.then((a, b, c) => { - // $ExpectType string - a[0]; - // $ExpectType boolean - a[1]; - // $ExpectType string - b[0]; - // $ExpectType boolean - b[1]; - // $ExpectType string - c[0]; - // $ExpectType boolean - c[1]; + a[0]; // $ExpectType string + a[1]; // $ExpectType boolean + b[0]; // $ExpectType string + b[1]; // $ExpectType boolean + c[0]; // $ExpectType string + c[1]; // $ExpectType boolean }); w.catch((a, b, c) => { - // $ExpectType Error - a[0]; - // $ExpectType any - a[1]; - // $ExpectType Error - b[0]; - // $ExpectType any - b[1]; - // $ExpectType Error - c[0]; - // $ExpectType any - c[1]; + a[0]; // $ExpectType Error + a[1]; // $ExpectType any + b[0]; // $ExpectType Error + b[1]; // $ExpectType any + c[0]; // $ExpectType Error + c[1]; // $ExpectType any }); w.then(null, null, (a, b, c) => { - // $ExpectType never - a; - // $ExpectType never - b; - // $ExpectType never - c; + a; // $ExpectType never + b; // $ExpectType never + c; // $ExpectType never }); } @@ -4628,30 +4615,20 @@ function JQueryStatic() { const w = $.when(t, u); w.then((a, b) => { - // $ExpectType string - a[0]; - // $ExpectType boolean - a[1]; - // $ExpectType string - b[0]; - // $ExpectType boolean - b[1]; + a[0]; // $ExpectType string + a[1]; // $ExpectType boolean + b[0]; // $ExpectType string + b[1]; // $ExpectType boolean }); w.catch((a, b) => { - // $ExpectType Error - a[0]; - // $ExpectType any - a[1]; - // $ExpectType Error - b[0]; - // $ExpectType any - b[1]; + a[0]; // $ExpectType Error + a[1]; // $ExpectType any + b[0]; // $ExpectType Error + b[1]; // $ExpectType any }); w.then(null, null, (a, b) => { - // $ExpectType never - a; - // $ExpectType never - b; + a; // $ExpectType never + b; // $ExpectType never }); } @@ -4660,22 +4637,16 @@ function JQueryStatic() { const w = $.when(t); w.then((a, b) => { - // $ExpectType string - a; - // $ExpectType boolean - b; + a; // $ExpectType string + b; // $ExpectType boolean }); w.catch((a, b) => { - // $ExpectType Error - a; - // $ExpectType any - b; + a; // $ExpectType Error + b; // $ExpectType any }); w.then(null, null, (a, b) => { - // $ExpectType never - a; - // $ExpectType never - b; + a; // $ExpectType never + b; // $ExpectType never }); } } @@ -5400,7 +5371,26 @@ function jqXHR() { } } -function Promise3(p: JQuery.Promise3) { +function Promise3() { + interface I1 { kind: 'I1'; } + interface I2 { kind: 'I2'; } + interface I3 { kind: 'I3'; } + interface I4 { kind: 'I4'; } + interface I5 { kind: 'I5'; } + interface I6 { kind: 'I6'; } + interface I7 { kind: 'I7'; } + interface I8 { kind: 'I8'; } + interface I9 { kind: 'I9'; } + + const p: JQuery.Promise3 = {} as any; + const p1: JQuery.Promise3 = {} as any; + const p2: JQuery.Promise3 = {} as any; + const p3: JQuery.Promise3 = {} as any; + + const t1: JQuery.Thenable = {} as any; + const t2: JQuery.Thenable = {} as any; + const t3: JQuery.Thenable = {} as any; + function then() { p.then((a, b, c) => { a; // $ExpectType string @@ -5450,7 +5440,7 @@ function Promise3(p: JQuery.Promise3 { a; // $ExpectType string @@ -5460,12 +5450,6 @@ function Promise3(p: JQuery.Promise3 { - a; // $ExpectType Error - b; // $ExpectType string - c; // $ExpectType Function }); p.then(null, (a, b, c) => { @@ -5474,29 +5458,29 @@ function Promise3(p: JQuery.Promise3 { - a; // $ExpectType string - b; // $ExpectType JQuery - c; // $ExpectType any + p.then(null, (a, b, c) => { + a; // $ExpectType Error + b; // $ExpectType string + c; // $ExpectType Function }); - p.then((a, b, c) => { - a; // $ExpectType string - b; // $ExpectType JQuery - c; // $ExpectType any - }, null); - p.then((a, b, c) => { a; // $ExpectType string b; // $ExpectType JQuery c; // $ExpectType any }, null, null); - p.then(null); + p.then((a, b, c) => { + a; // $ExpectType string + b; // $ExpectType JQuery + c; // $ExpectType any + }, null); - p.then(null, null); - - p.then(null, null, null); + p.then((a, b, c) => { + a; // $ExpectType string + b; // $ExpectType JQuery + c; // $ExpectType any + }); function doneFilter() { p.then(() => { @@ -5559,48 +5543,196 @@ function Promise3(p: JQuery.Promise3 { - return 1; - }; - const thenable = () => { - const t: JQuery.Thenable = { - then() { - return Promise.resolve('myValue'); - } - }; + // (value, value) + { + const q = p.then(() => { + return 1; + }, () => { + return 1; + }); - return t; - }; - const promise3 = () => { - return $.ajax('/echo/json') as JQuery.jqXHR; - }; + q.then((a) => { + a; // $ExpectType number + }, (a) => { + a; // $ExpectType never + }, (a, b, c) => { + a; // $ExpectType never + b; // $ExpectType never + c; // $ExpectType never + }); + } - // $ExpectType Promise3 - $.ajax('/echo/json').then(value, value); + // (Thenable, Thenable) + { + const q = p.then(() => { + return t1; + }, () => { + return t2; + }); - // $ExpectType Promise3 - $.ajax('/echo/json').then(thenable, thenable); + q.then((a) => { + a; // $ExpectType I1 | I2 + }, (a) => { + a; // $ExpectType never + }, (a, b, c) => { + a; // $ExpectType never + b; // $ExpectType never + c; // $ExpectType never + }); + } - // $ExpectType Promise3, never, SuccessTextStatus, ErrorTextStatus, never, jqXHR, string, never> - $.ajax('/echo/json').then(promise3, promise3); + // (Promise3, Promise3) + { + const q = p.then(() => { + return p1; + }, () => { + return p2; + }); - // $ExpectType Promise3 - $.ajax('/echo/json').then(value, thenable); + q.then((a, b, c) => { + a; // $ExpectType I1 | I2 + b; // $ExpectType I4 | I5 + c; // $ExpectType I7 | I8 + }, (a, b, c) => { + a; // $ExpectType I2 | I3 + b; // $ExpectType I5 | I6 + c; // $ExpectType I8 | I9 + }, (a, b, c) => { + a; // $ExpectType I3 | I4 + b; // $ExpectType I6 | I7 + c; // $ExpectType I1 | I9 + }); + } - // $ExpectType Promise3 - $.ajax('/echo/json').then(thenable, value); + // (value, Thenable) + { + const q = p.then(() => { + return 1; + }, () => { + return t1; + }); - // $ExpectType Promise3, never, SuccessTextStatus, ErrorTextStatus, never, jqXHR, string, never> - $.ajax('/echo/json').then(value, promise3); + q.then((a) => { + a; // $ExpectType number | I1 + }, (a) => { + a; // never + }, (a, b, c) => { + a; // $ExpectType never + b; // $ExpectType never + c; // $ExpectType never + }); + } - // $ExpectType Promise3, never, SuccessTextStatus, ErrorTextStatus, never, jqXHR, string, never> - $.ajax('/echo/json').then(promise3, value); + // (Thenable, value) + { + const q = p.then(() => { + return t1; + }, () => { + return 1; + }); - // $ExpectType Promise3, never, SuccessTextStatus, ErrorTextStatus, never, jqXHR, string, never> - $.ajax('/echo/json').then(thenable, promise3); + q.then((a) => { + a; // $ExpectType number | I1 + }, (a) => { + a; // never + }, (a, b, c) => { + a; // $ExpectType never + b; // $ExpectType never + c; // $ExpectType never + }); + } - // $ExpectType Promise3, never, SuccessTextStatus, ErrorTextStatus, never, jqXHR, string, never> - $.ajax('/echo/json').then(promise3, thenable); + // (value, Promise3) + { + const q = p.then(() => { + return 1; + }, () => { + return p1; + }); + + q.then((a, b, c) => { + a; // $ExpectType number | I1 + b; // $ExpectType I4 + c; // $ExpectType I7 + }, (a, b, c) => { + a; // $ExpectType I2 + b; // $ExpectType I5 + c; // $ExpectType I8 + }, (a, b, c) => { + a; // $ExpectType I3 + b; // $ExpectType I6 + c; // $ExpectType I9 + }); + } + + // (Promise3, value) + { + const q = p.then(() => { + return p1; + }, () => { + return 1; + }); + + q.then((a, b, c) => { + a; // $ExpectType number | I1 + b; // $ExpectType I4 + c; // $ExpectType I7 + }, (a, b, c) => { + a; // $ExpectType I2 + b; // $ExpectType I5 + c; // $ExpectType I8 + }, (a, b, c) => { + a; // $ExpectType I3 + b; // $ExpectType I6 + c; // $ExpectType I9 + }); + } + + // (Thenable, Promise3) + { + const q = p.then(() => { + return t1; + }, () => { + return p2; + }); + + q.then((a, b, c) => { + a; // $ExpectType I1 | I2 + b; // $ExpectType I5 + c; // $ExpectType I8 + }, (a, b, c) => { + a; // $ExpectType I3 + b; // $ExpectType I6 + c; // $ExpectType I9 + }, (a, b, c) => { + a; // $ExpectType I4 + b; // $ExpectType I7 + c; // $ExpectType I1 + }); + } + + // (Promise3, Thenable) + { + const q = p.then(() => { + return p1; + }, () => { + return t2; + }); + + q.then((a, b, c) => { + a; // $ExpectType I1 | I2 + b; // $ExpectType I4 + c; // $ExpectType I7 + }, (a, b, c) => { + a; // $ExpectType I2 + b; // $ExpectType I5 + c; // $ExpectType I8 + }, (a, b, c) => { + a; // $ExpectType I3 + b; // $ExpectType I6 + c; // $ExpectType I9 + }); + } } }