Skip to content

Commit

Permalink
Allow Bluebird to be assignable to ES2016 Promise. (#11036)
Browse files Browse the repository at this point in the history
* Allow Bluebird to be assignable to ES2016 Promise.

Add yet another one `.then` overloadings.

* bluebird: Fix .then overloadings
  • Loading branch information
Strate authored and vvakame committed Sep 7, 2016
1 parent 823c53c commit 9b111fd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions bluebird/bluebird-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ var voidProm: Promise<void>;

var fooProm: Promise<Foo>;
var barProm: Promise<Bar>;
var barOrVoidProm: Promise<Bar | void>;
var fooOrBarProm: Promise<Foo|Bar>;
var bazProm: Promise<Baz>;

Expand Down Expand Up @@ -221,12 +222,12 @@ barProm = fooProm.then((value: Foo) => {
}, (reason: any) => {
return barProm;
});
barProm = fooProm.then((value: Foo) => {
barOrVoidProm = fooProm.then((value: Foo) => {
return bar;
}, (reason: any) => {
return;
});
barProm = fooProm.then((value: Foo) => {
barOrVoidProm = fooProm.then((value: Foo) => {
return bar;
}, (reason: any) => {
return voidProm;
Expand Down
6 changes: 4 additions & 2 deletions bluebird/bluebird.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ class Bluebird<R> implements Bluebird.Thenable<R>, Bluebird.Inspection<R> {
/**
* Promises/A+ `.then()`. Returns a new promise chained from this promise. The new promise will be rejected or resolved dedefer on the passed `fulfilledHandler`, `rejectedHandler` and the state of this promise.
*/
then<U>(onFulfill: (value: R) => U | Bluebird.Thenable<U>, onReject?: (error: any) => U | Bluebird.Thenable<U>): Bluebird<U>;
then<U>(onFulfill: (value: R) => U | Bluebird.Thenable<U>, onReject?: (error: any) => void | Bluebird.Thenable<void>): Bluebird<U>;
then<U1, U2>(onFulfill: (value: R) => U1 | Bluebird.Thenable<U1>, onReject: (error: any) => U2 | Bluebird.Thenable<U2>): Bluebird<U1 | U2>;
then<U>(onFulfill: (value: R) => U | Bluebird.Thenable<U>, onReject: (error: any) => U | Bluebird.Thenable<U>): Bluebird<U>;
then<U>(onFulfill: (value: R) => U | Bluebird.Thenable<U>): Bluebird<U>;
then(): Bluebird<R>;

/**
* This is a catch-all exception handler, shortcut for calling `.then(null, handler)` on this promise. Any exception happening in a `.then`-chain will propagate to nearest `.catch` handler.
Expand Down

0 comments on commit 9b111fd

Please sign in to comment.