From 79746b418281b8fc67b5dfbdfb253a6f7ce2f9ef Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Mon, 26 Jun 2017 09:19:18 -0400 Subject: [PATCH] [jquery] when() does not emit progress notifications. --- types/jquery/index.d.ts | 58 +++++------ types/jquery/jquery-tests.ts | 192 +++++++++++++++++++++++------------ 2 files changed, 152 insertions(+), 98 deletions(-) diff --git a/types/jquery/index.d.ts b/types/jquery/index.d.ts index 64111d5b69..bae24d9780 100644 --- a/types/jquery/index.d.ts +++ b/types/jquery/index.d.ts @@ -3273,9 +3273,11 @@ interface JQueryStatic { when - (deferredT: TR1 | JQuery.Thenable | JQuery.Promise, - deferredU: UR1 | JQuery.Thenable | JQuery.Promise, - deferredV: VR1 | JQuery.Thenable | JQuery.Promise): JQuery.Promise3; + (deferredT: JQuery.Promise | JQuery.Thenable | TR1, + deferredU: JQuery.Promise | JQuery.Thenable | UR1, + deferredV: JQuery.Promise | JQuery.Thenable | VR1): JQuery.Promise3; /** * Provides a way to execute callback functions based on zero or more Thenable objects, usually * Deferred objects that represent asynchronous events. @@ -3292,14 +3294,14 @@ interface JQueryStatic { VR1 = never, VJ1 = never, VN1 = never, VR2 = never, VJ2 = never, VN2 = never, VR3 = never, VJ3 = never, VN3 = never> - (deferredT: JQuery.Promise2 | - JQuery.Promise3, - deferredU: JQuery.Promise2 | - JQuery.Promise3, - deferredV: JQuery.Promise2 | - JQuery.Promise3): JQuery.Promise3<[TR1, TR2, TR3], [TJ1, TJ2, TJ3], [TN1, TN2, TN3], - [UR1, UR2, UR3], [UJ1, UJ2, UJ3], [UN1, UN2, UN3], - [VR1, VR2, VR3], [VJ1, VJ2, VJ3], [VN1, VN2, VN3]>; + (deferredT: JQuery.Promise3 | + JQuery.Promise2, + deferredU: JQuery.Promise3 | + JQuery.Promise2, + deferredV: JQuery.Promise3 | + JQuery.Promise2): JQuery.Promise3<[TR1, TR2, TR3], [TJ1, TJ2, TJ3], never, + [UR1, UR2, UR3], [UJ1, UJ2, UJ3], never, + [VR1, VR2, VR3], [VJ1, VJ2, VJ3], never>; /** * Provides a way to execute callback functions based on zero or more Thenable objects, usually * Deferred objects that represent asynchronous events. @@ -3309,8 +3311,9 @@ interface JQueryStatic { */ when - (deferredT: TR1 | JQuery.Thenable | JQuery.Promise, - deferredU: UR1 | JQuery.Thenable | JQuery.Promise): JQuery.Promise2; + (deferredT: JQuery.Promise | JQuery.Thenable | TR1, + deferredU: JQuery.Promise | JQuery.Thenable | UR1): JQuery.Promise2; /** * Provides a way to execute callback functions based on zero or more Thenable objects, usually * Deferred objects that represent asynchronous events. @@ -3324,11 +3327,11 @@ interface JQueryStatic { UR1 = never, UJ1 = never, UN1 = never, UR2 = never, UJ2 = never, UN2 = never, UR3 = never, UJ3 = never, UN3 = never> - (deferredT: JQuery.Promise2 | - JQuery.Promise3, - deferredU: JQuery.Promise2 | - JQuery.Promise3): JQuery.Promise2<[TR1, TR2, TR3], [TJ1, TJ2, TJ3], [TN1, TN2, TN3], - [UR1, UR2, UR3], [UJ1, UJ2, UJ3], [UN1, UN2, UN3]>; + (deferredT: JQuery.Promise3 | + JQuery.Promise2, + deferredU: JQuery.Promise3 | + JQuery.Promise2): JQuery.Promise2<[TR1, TR2, TR3], [TJ1, TJ2, TJ3], never, + [UR1, UR2, UR3], [UJ1, UJ2, UJ3], never>; /** * Provides a way to execute callback functions based on zero or more Thenable objects, usually * Deferred objects that represent asynchronous events. @@ -3336,7 +3339,7 @@ interface JQueryStatic { * @see {@link https://api.jquery.com/jQuery.when/} * @since 1.5 */ - when(deferred: TR1 | JQuery.Thenable | JQuery.Promise): JQuery.Promise; + when(deferred: JQuery.Promise | JQuery.Thenable | TR1): JQuery.Promise; /** * Provides a way to execute callback functions based on zero or more Thenable objects, usually * Deferred objects that represent asynchronous events. @@ -3346,18 +3349,9 @@ interface JQueryStatic { */ when - (deferredT: JQuery.Promise3): JQuery.Promise3; - /** - * Provides a way to execute callback functions based on zero or more Thenable objects, usually - * Deferred objects that represent asynchronous events. - * - * @see {@link https://api.jquery.com/jQuery.when/} - * @since 1.5 - */ - when - (deferredT: JQuery.Promise2): JQuery.Promise2; + TR3 = never, TJ3 = never, TN3 = never> + (deferredT: JQuery.Promise3 | + JQuery.Promise2): JQuery.Promise3; /** * Provides a way to execute callback functions based on zero or more Thenable objects, usually * Deferred objects that represent asynchronous events. @@ -3366,7 +3360,7 @@ interface JQueryStatic { * @see {@link https://api.jquery.com/jQuery.when/} * @since 1.5 */ - when(...deferreds: Array>): JQuery.Promise; + when(...deferreds: Array>): JQuery.Promise; } declare namespace JQuery { diff --git a/types/jquery/jquery-tests.ts b/types/jquery/jquery-tests.ts index 8a6710a2fd..609f65c6f1 100644 --- a/types/jquery/jquery-tests.ts +++ b/types/jquery/jquery-tests.ts @@ -4449,27 +4449,51 @@ function JQueryStatic() { const w = $.when(t, u, v); w.then((a, b, c) => { - // $ExpectType [string, SuccessTextStatus, jqXHR] - a; - // $ExpectType [number, SuccessTextStatus, jqXHR] - b; - // $ExpectType [boolean, SuccessTextStatus, jqXHR] - c; + // $ExpectType string + a[0]; + // $ExpectType SuccessTextStatus + a[1]; + // $ExpectType jqXHR + a[2]; + // $ExpectType number + b[0]; + // $ExpectType SuccessTextStatus + b[1]; + // $ExpectType jqXHR + b[2]; + // $ExpectType boolean + c[0]; + // $ExpectType SuccessTextStatus + c[1]; + // $ExpectType jqXHR + c[2]; }); w.catch((a, b, c) => { - // $ExpectType [jqXHR, ErrorTextStatus, string] - a; - // $ExpectType [jqXHR, ErrorTextStatus, string] - b; - // $ExpectType [jqXHR, ErrorTextStatus, string] - c; + // $ExpectType jqXHR + a[0]; + // $ExpectType ErrorTextStatus + a[1]; + // $ExpectType string + a[2]; + // $ExpectType jqXHR + b[0]; + // $ExpectType ErrorTextStatus + b[1]; + // $ExpectType string + b[2]; + // $ExpectType jqXHR + c[0]; + // $ExpectType ErrorTextStatus + c[1]; + // $ExpectType string + c[2]; }); w.then(null, null, (a, b, c) => { - // $ExpectType [never, never, never] + // $ExpectType never a; - // $ExpectType [never, never, never] + // $ExpectType never b; - // $ExpectType [never, never, never] + // $ExpectType never c; }); } @@ -4479,21 +4503,37 @@ function JQueryStatic() { const w = $.when(t, u); w.then((a, b) => { - // $ExpectType [string, SuccessTextStatus, jqXHR] - a; - // $ExpectType [number, SuccessTextStatus, jqXHR] - b; + // $ExpectType string + a[0]; + // $ExpectType SuccessTextStatus + a[1]; + // $ExpectType jqXHR + a[2]; + // $ExpectType number + b[0]; + // $ExpectType SuccessTextStatus + b[1]; + // $ExpectType jqXHR + b[2]; }); w.catch((a, b) => { - // $ExpectType [jqXHR, ErrorTextStatus, string] - a; - // $ExpectType [jqXHR, ErrorTextStatus, string] - b; + // $ExpectType jqXHR + a[0]; + // $ExpectType ErrorTextStatus + a[1]; + // $ExpectType string + a[2]; + // $ExpectType jqXHR + b[0]; + // $ExpectType ErrorTextStatus + b[1]; + // $ExpectType string + b[2]; }); w.then(null, null, (a, b) => { - // $ExpectType [never, never, never] + // $ExpectType never a; - // $ExpectType [never, never, never] + // $ExpectType never b; }); } @@ -4539,27 +4579,39 @@ function JQueryStatic() { const w = $.when(t, u, v); w.then((a, b, c) => { - // $ExpectType [string, boolean, never] - a; - // $ExpectType [string, boolean, never] - b; - // $ExpectType [string, boolean, never] - 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]; }); w.catch((a, b, c) => { - // $ExpectType [Error, any, never] - a; - // $ExpectType [Error, any, never] - b; - // $ExpectType [Error, any, never] - 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]; }); w.then(null, null, (a, b, c) => { - // $ExpectType [number, any, never] + // $ExpectType never a; - // $ExpectType [number, any, never] + // $ExpectType never b; - // $ExpectType [number, any, never] + // $ExpectType never c; }); } @@ -4569,21 +4621,29 @@ function JQueryStatic() { const w = $.when(t, u); w.then((a, b) => { - // $ExpectType [string, boolean, never] - a; - // $ExpectType [string, boolean, never] - b; + // $ExpectType string + a[0]; + // $ExpectType boolean + a[1]; + // $ExpectType string + b[0]; + // $ExpectType boolean + b[1]; }); w.catch((a, b) => { - // $ExpectType [Error, any, never] - a; - // $ExpectType [Error, any, never] - b; + // $ExpectType Error + a[0]; + // $ExpectType any + a[1]; + // $ExpectType Error + b[0]; + // $ExpectType any + b[1]; }); w.then(null, null, (a, b) => { - // $ExpectType [number, any, never] + // $ExpectType never a; - // $ExpectType [number, any, never] + // $ExpectType never b; }); } @@ -4605,9 +4665,9 @@ function JQueryStatic() { b; }); w.then(null, null, (a, b) => { - // $ExpectType number + // $ExpectType never a; - // $ExpectType any + // $ExpectType never b; }); } @@ -4620,14 +4680,12 @@ function JQueryStatic() { // $ExpectType string value; }); - w.catch(reason => { // $ExpectType Error reason; }); - w.then(null, null, value => { - // $ExpectType number + // $ExpectType never value; }); } @@ -4676,11 +4734,7 @@ function JQueryStatic() { } $.when().then(() => { - const f = first(); - // $ExpectType Promise - f; - - return f; + return first(); }).then((value) => { // $ExpectType string value; @@ -4699,12 +4753,18 @@ function JQueryStatic() { const task2 = this.runTask2(); const task3 = this.runTask3(); - // $ExpectType Promise - task1; - // $ExpectType Promise - task2; - // $ExpectType Promise - task3; + task1.then(value => { + // $ExpectType One + value; + }); + task2.then(value => { + // $ExpectType Two + value; + }); + task3.then(value => { + // $ExpectType Three + value; + }); $.when(task1, task2, task3) .done((r1, r2, r3) => {