From db02b8009e6aae72677c8058a1ae7c0e37488943 Mon Sep 17 00:00:00 2001 From: patricklx Date: Thu, 13 Aug 2020 17:50:05 +0200 Subject: [PATCH 1/5] fix then -> static all e.g. `Promise.resolve([x1, x2]).all().then([x1, x2])` --- types/bluebird/bluebird-tests.ts | 8 ++++++++ types/bluebird/index.d.ts | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/types/bluebird/bluebird-tests.ts b/types/bluebird/bluebird-tests.ts index ad60766287244a..707cc26dfd4334 100644 --- a/types/bluebird/bluebird-tests.ts +++ b/types/bluebird/bluebird-tests.ts @@ -244,6 +244,14 @@ barProm = barProm.then((value: Bar) => { return Bluebird.resolve(bar); }); +Bluebird.resolve() + .then(() => ["" as string, Bluebird.resolve(0 as number)]) + .all() + .then(([x1, x2]) => { + const y1: string = x1; + const y2: number = x2; + }); + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // $ExpectType Bluebird diff --git a/types/bluebird/index.d.ts b/types/bluebird/index.d.ts index d22c94406ab38b..a9543e5a9c0989 100644 --- a/types/bluebird/index.d.ts +++ b/types/bluebird/index.d.ts @@ -58,7 +58,12 @@ declare class Bluebird implements PromiseLike, Bluebird.Inspection { * The new promise will be rejected or resolved depending on the passed `fulfilledHandler`, `rejectedHandler` and the state of this promise. */ // Based on PromiseLike.then, but returns a Bluebird instance. - then(onFulfill?: (value: R) => Resolvable, onReject?: (error: any) => Resolvable): Bluebird; // For simpler signature help. + then(onFulfill?: (value: R) => [T1, T2, T3, T4, T5], onReject?: (error: any) => [T1, T2, T3, T4, T5]): Bluebird<[T1, T2, T3, T4, T5]>; + then(onFulfill?: (value: R) => [T1, T2, T3, T4], onReject?: (error: any) => [T1, T2, T3, T4]): Bluebird<[T1, T2, T3, T4]>; + then(onFulfill?: (value: R) => [T1, T2, T3], onReject?: (error: any) => [T1, T2, T3]): Bluebird<[T1, T2, T3]>; + then(onFulfill?: (value: R) => [T1, T2], onReject?: (error: any) => [T1, T2]): Bluebird<[T1, T2]>; + then(onFulfill?: (value: R) => [T1], onReject?: (error: any) => [T1]): Bluebird<[T1]>; + then(onFulfill?: (value: R) => Resolvable, onReject?: (error: any) => Resolvable): Bluebird; then( onfulfilled?: ((value: R) => Resolvable) | null, onrejected?: ((reason: any) => Resolvable) | null From 4df8db34f8d8379f163f77370518d27a90216602 Mon Sep 17 00:00:00 2001 From: patrick Date: Thu, 20 Aug 2020 13:55:41 +0200 Subject: [PATCH 2/5] use variadic --- types/bluebird/bluebird-tests.ts | 2 +- types/bluebird/index.d.ts | 15 ++++----------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/types/bluebird/bluebird-tests.ts b/types/bluebird/bluebird-tests.ts index 707cc26dfd4334..fb313f54dec086 100644 --- a/types/bluebird/bluebird-tests.ts +++ b/types/bluebird/bluebird-tests.ts @@ -245,7 +245,7 @@ barProm = barProm.then((value: Bar) => { }); Bluebird.resolve() - .then(() => ["" as string, Bluebird.resolve(0 as number)]) + .then(() => ["", Bluebird.resolve(0)]) .all() .then(([x1, x2]) => { const y1: string = x1; diff --git a/types/bluebird/index.d.ts b/types/bluebird/index.d.ts index a9543e5a9c0989..30b698b152b03c 100644 --- a/types/bluebird/index.d.ts +++ b/types/bluebird/index.d.ts @@ -58,12 +58,8 @@ declare class Bluebird implements PromiseLike, Bluebird.Inspection { * The new promise will be rejected or resolved depending on the passed `fulfilledHandler`, `rejectedHandler` and the state of this promise. */ // Based on PromiseLike.then, but returns a Bluebird instance. - then(onFulfill?: (value: R) => [T1, T2, T3, T4, T5], onReject?: (error: any) => [T1, T2, T3, T4, T5]): Bluebird<[T1, T2, T3, T4, T5]>; - then(onFulfill?: (value: R) => [T1, T2, T3, T4], onReject?: (error: any) => [T1, T2, T3, T4]): Bluebird<[T1, T2, T3, T4]>; - then(onFulfill?: (value: R) => [T1, T2, T3], onReject?: (error: any) => [T1, T2, T3]): Bluebird<[T1, T2, T3]>; - then(onFulfill?: (value: R) => [T1, T2], onReject?: (error: any) => [T1, T2]): Bluebird<[T1, T2]>; - then(onFulfill?: (value: R) => [T1], onReject?: (error: any) => [T1]): Bluebird<[T1]>; - then(onFulfill?: (value: R) => Resolvable, onReject?: (error: any) => Resolvable): Bluebird; + then(onFulfill?: (value: R) => Resolvable<[...T]>, onReject?: (error: any) => Resolvable<[...T]>): Bluebird<[...T]>; + then(onFulfill?: (value: R) => Resolvable, onReject?: (error: any) => Resolvable): Bluebird; then( onfulfilled?: ((value: R) => Resolvable) | null, onrejected?: ((reason: any) => Resolvable) | null @@ -571,11 +567,8 @@ declare class Bluebird implements PromiseLike, Bluebird.Inspection { /** * Same as calling `Promise.all(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. */ - all(this: Bluebird<[Resolvable, Resolvable, Resolvable, Resolvable, Resolvable]>): Bluebird<[T1, T2, T3, T4, T5]>; - all(this: Bluebird<[Resolvable, Resolvable, Resolvable, Resolvable]>): Bluebird<[T1, T2, T3, T4]>; - all(this: Bluebird<[Resolvable, Resolvable, Resolvable]>): Bluebird<[T1, T2, T3]>; - all(this: Bluebird<[Resolvable, Resolvable]>): Bluebird<[T1, T2]>; - all(this: Bluebird<[Resolvable]>): Bluebird<[T1]>; + + all(this: Bluebird<[...T]>): Bluebird<{ [P in keyof T]: T[P] extends Resolvable ? U : T[P] }>; all(this: Bluebird>>): Bluebird; /** From e585579b23e636972a79ff31b86d037a63cf47c3 Mon Sep 17 00:00:00 2001 From: patrick Date: Thu, 20 Aug 2020 14:16:32 +0200 Subject: [PATCH 3/5] fix --- types/bluebird/bluebird-tests.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/bluebird/bluebird-tests.ts b/types/bluebird/bluebird-tests.ts index fb313f54dec086..dda3bfbf1fce2c 100644 --- a/types/bluebird/bluebird-tests.ts +++ b/types/bluebird/bluebird-tests.ts @@ -244,6 +244,7 @@ barProm = barProm.then((value: Bar) => { return Bluebird.resolve(bar); }); +// Minimum TypeScript Version: 4.0 Bluebird.resolve() .then(() => ["", Bluebird.resolve(0)]) .all() From 4c253efb8e4dbf5ca6f64eb57951e0d1f65e9c81 Mon Sep 17 00:00:00 2001 From: patrick Date: Thu, 20 Aug 2020 14:31:42 +0200 Subject: [PATCH 4/5] fix --- types/bluebird/bluebird-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/bluebird/bluebird-tests.ts b/types/bluebird/bluebird-tests.ts index dda3bfbf1fce2c..446424ac7e1c20 100644 --- a/types/bluebird/bluebird-tests.ts +++ b/types/bluebird/bluebird-tests.ts @@ -4,6 +4,7 @@ // Note: keep both static and instance members inline (so similar) // Note: try to maintain the ordering and separators, and keep to the pattern +// Minimum TypeScript Version: 4.0 import * as Bluebird from "bluebird"; @@ -244,7 +245,6 @@ barProm = barProm.then((value: Bar) => { return Bluebird.resolve(bar); }); -// Minimum TypeScript Version: 4.0 Bluebird.resolve() .then(() => ["", Bluebird.resolve(0)]) .all() From bc574372c5fd103179e12c3e1ccfcdcff5e37fb1 Mon Sep 17 00:00:00 2001 From: patrick Date: Thu, 20 Aug 2020 14:39:29 +0200 Subject: [PATCH 5/5] fix --- types/bluebird/bluebird-tests.ts | 3 ++- types/bluebird/index.d.ts | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/types/bluebird/bluebird-tests.ts b/types/bluebird/bluebird-tests.ts index 446424ac7e1c20..34efc81e8c1ae2 100644 --- a/types/bluebird/bluebird-tests.ts +++ b/types/bluebird/bluebird-tests.ts @@ -1,10 +1,11 @@ // Tests by: Bart van der Schoor +// Minimum TypeScript Version: 4.0 // Note: replicate changes to all overloads in both definition and test file // Note: keep both static and instance members inline (so similar) // Note: try to maintain the ordering and separators, and keep to the pattern -// Minimum TypeScript Version: 4.0 + import * as Bluebird from "bluebird"; diff --git a/types/bluebird/index.d.ts b/types/bluebird/index.d.ts index 30b698b152b03c..a3afa82b063038 100644 --- a/types/bluebird/index.d.ts +++ b/types/bluebird/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/petkaantonov/bluebird // Definitions by: Leonard Hecker // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 3.2 +// TypeScript Version: 4.0 /*! * The code following this comment originates from: @@ -72,6 +72,7 @@ declare class Bluebird implements PromiseLike, Bluebird.Inspection { * * Alias `.caught();` for compatibility with earlier ECMAScript version. */ + catch(onReject?: (error: any) => [...T] | undefined | null): Bluebird<[...T] | R>; catch(onReject: ((error: any) => Resolvable) | undefined | null): Bluebird; /** @@ -678,6 +679,7 @@ declare class Bluebird implements PromiseLike, Bluebird.Inspection { /** * Create a promise that is resolved with the given `value`. If `value` is a thenable or promise, the returned promise will assume its state. */ + static resolve(value: Bluebird<[...T]>): Bluebird<[...T]>; static resolve(): Bluebird; static resolve(value: Resolvable): Bluebird;