From d1d801b96e3c0d36b2c7f2e703c690abd5fc7580 Mon Sep 17 00:00:00 2001 From: Artur Eshenbrener Date: Fri, 7 Oct 2016 11:24:56 +0300 Subject: [PATCH] Improve catch with constructor filter. Add arguments to constructor's `new()` signature + tests --- bluebird/bluebird-tests.ts | 12 ++++++++++++ bluebird/bluebird.d.ts | 8 ++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/bluebird/bluebird-tests.ts b/bluebird/bluebird-tests.ts index 7970ee0fe5..318e6f8a4c 100644 --- a/bluebird/bluebird-tests.ts +++ b/bluebird/bluebird-tests.ts @@ -347,6 +347,18 @@ fooOrBarProm = fooProm.caught(Promise.CancellationError, (reason: any) => { }) } +{ + class CustomErrorWithConstructor extends Error { + constructor(public arg1: boolean, public arg2: number) { + super(); + }; + } + fooProm = fooProm.catch(CustomErrorWithConstructor, reason => { + let a: boolean = reason.arg1; + let b: number = reason.arg2; + }) +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - barProm = fooProm.error((reason: any) => { diff --git a/bluebird/bluebird.d.ts b/bluebird/bluebird.d.ts index 6562046138..5ee5c0cad4 100644 --- a/bluebird/bluebird.d.ts +++ b/bluebird/bluebird.d.ts @@ -75,11 +75,11 @@ class Bluebird implements Bluebird.Thenable, Bluebird.Inspection { 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 () => E, onReject: (error: E) => R | Bluebird.Thenable | void | Bluebird.Thenable): Bluebird; - caught(ErrorClass: new () => E, onReject: (error: E) => R | Bluebird.Thenable | void | 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 () => E, onReject: (error: E) => U | Bluebird.Thenable): Bluebird; - caught(ErrorClass: new () => E, onReject: (error: E) => U | 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;