diff --git a/bluebird-global/index.d.ts b/bluebird-global/index.d.ts index caf873510d..e4c4920501 100644 --- a/bluebird-global/index.d.ts +++ b/bluebird-global/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for bluebird 3.0 +// Type definitions for bluebird 3.5 // Project: https://github.com/petkaantonov/bluebird // Definitions by: d-ph // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -76,6 +76,7 @@ declare global { spread: typeof Bluebird.prototype.spread; suppressUnhandledRejections: typeof Bluebird.prototype.suppressUnhandledRejections; tap: typeof Bluebird.prototype.tap; + tapCatch: typeof Bluebird.prototype.tapCatch; // then: typeof Bluebird.prototype.then; thenReturn: typeof Bluebird.prototype.thenReturn; thenThrow: typeof Bluebird.prototype.thenThrow; diff --git a/bluebird/bluebird-tests.ts b/bluebird/bluebird-tests.ts index ea1ea69882..c08a7bdc6b 100644 --- a/bluebird/bluebird-tests.ts +++ b/bluebird/bluebird-tests.ts @@ -151,6 +151,10 @@ var BlueBird: typeof Promise; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +var version: string = Promise.version; + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + var nodeCallbackFunc = (callback: (err: any, result: string) => void) => {} var nodeCallbackFuncErrorOnly = (callback: (err: any) => void) => {} @@ -336,14 +340,12 @@ fooOrBarProm = fooProm.caught(Promise.CancellationError, (reason: any) => { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -{ - class CustomError extends Error { - public customField: number; - } - fooProm = fooProm.catch(CustomError, reason => { - let a: number = reason.customField - }) +class CustomError extends Error { + public customField: number; } +fooProm = fooProm.catch(CustomError, reason => { + let a: number = reason.customField +}) { class CustomErrorWithConstructor extends Error { @@ -433,6 +435,24 @@ fooProm = fooProm.tap(() => { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +fooProm = fooProm.tapCatch((err) => { + return "foo"; +}); + +fooProm = fooProm.tapCatch(err => { + return Promise.resolve("foo"); +}); + +fooProm.tapCatch(CustomError, (err: CustomError) => { + return err.customField; +}); + +fooProm.tapCatch((e: any) => e instanceof CustomError, (err: CustomError) => { + return err.customField; +}); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + fooProm = fooProm.delay(num); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/bluebird/index.d.ts b/bluebird/index.d.ts index 2faa74e285..ecacedfd0d 100644 --- a/bluebird/index.d.ts +++ b/bluebird/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for bluebird 3.0.0 +// Type definitions for bluebird 3.5.0 // Project: https://github.com/petkaantonov/bluebird // Definitions by: Leonard Hecker // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -68,19 +68,19 @@ declare class Bluebird implements Bluebird.Thenable, Bluebird.Inspection boolean, onReject: (error: any) => R | Bluebird.Thenable | void | Bluebird.Thenable): Bluebird; caught(predicate: (error: any) => boolean, onReject: (error: any) => R | Bluebird.Thenable | void | Bluebird.Thenable): Bluebird; - + catch(predicate: (error: any) => boolean, onReject: (error: any) => U | Bluebird.Thenable): Bluebird; caught(predicate: (error: any) => boolean, onReject: (error: any) => U | Bluebird.Thenable): Bluebird; - + catch(ErrorClass: new (...args: any[]) => E, onReject: (error: E) => R | Bluebird.Thenable | void | Bluebird.Thenable): Bluebird; caught(ErrorClass: new (...args: any[]) => E, onReject: (error: E) => R | Bluebird.Thenable | void | Bluebird.Thenable): Bluebird; catch(ErrorClass: new (...args: any[]) => E, onReject: (error: E) => U | Bluebird.Thenable): Bluebird; caught(ErrorClass: new (...args: any[]) => E, onReject: (error: E) => U | Bluebird.Thenable): Bluebird; - + catch(predicate: Object, onReject: (error: any) => R | Bluebird.Thenable | void | Bluebird.Thenable): Bluebird; caught(predicate: Object, onReject: (error: any) => R | Bluebird.Thenable | void | Bluebird.Thenable): Bluebird; - + catch(predicate: Object, onReject: (error: any) => U | Bluebird.Thenable): Bluebird; caught(predicate: Object, onReject: (error: any) => U | Bluebird.Thenable): Bluebird; @@ -114,6 +114,14 @@ declare class Bluebird implements Bluebird.Thenable, Bluebird.Inspection(onFulFill: (value: R) => Bluebird.Thenable): Bluebird; tap(onFulfill: (value: R) => U): Bluebird; + /** + * Like `.catch()` but rethrows the error + */ + tapCatch(onReject: (error?: any) => U | Bluebird.Thenable | void | Bluebird.Thenable): Bluebird; + tapCatch(ErrorClass: new (...args: any[]) => E, onReject: (error: E) => U | Bluebird.Thenable | void | Bluebird.Thenable): Bluebird; + tapCatch(predicate: (error?: any) => boolean, onReject: (error?: any) => U | Bluebird.Thenable | void | Bluebird.Thenable): Bluebird; + + /** * Same as calling `Promise.delay(ms, this)`. */ @@ -321,7 +329,7 @@ declare class Bluebird implements Bluebird.Thenable, Bluebird.Inspection implements Bluebird.Thenable, Bluebird.Inspection