From 9a579744d2cd8fc66ad0d1aa7319cd6a7e56cb2f Mon Sep 17 00:00:00 2001 From: Brandon Furtwangler Date: Wed, 3 Feb 2016 08:59:20 -0800 Subject: [PATCH] bluebird: fixed inference issue with try/attempt --- bluebird/bluebird-1.0-tests.ts | 15 +++++++++++++++ bluebird/bluebird-1.0.d.ts | 6 ++---- bluebird/bluebird-tests.ts | 15 +++++++++++++++ bluebird/bluebird.d.ts | 6 ++---- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/bluebird/bluebird-1.0-tests.ts b/bluebird/bluebird-1.0-tests.ts index f04317f6ae..2aa795a4f3 100644 --- a/bluebird/bluebird-1.0-tests.ts +++ b/bluebird/bluebird-1.0-tests.ts @@ -504,7 +504,16 @@ fooArrProm = fooArrProm.filter((item: Foo) => { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +function getMaybePromise(): Foo|Promise { + return foo; +} +fooProm = Promise.try(() => { + return getMaybePromise(); +}); +fooProm = Promise.try(() => { + return getMaybePromise(); +}); fooProm = Promise.try(() => { return foo; }); @@ -529,6 +538,12 @@ fooProm = Promise.try(() => { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +fooProm = Promise.attempt(() => { + return getMaybePromise(); +}); +fooProm = Promise.attempt(() => { + return getMaybePromise(); +}); fooProm = Promise.attempt(() => { return foo; }); diff --git a/bluebird/bluebird-1.0.d.ts b/bluebird/bluebird-1.0.d.ts index b8287e57cc..2a43600d90 100644 --- a/bluebird/bluebird-1.0.d.ts +++ b/bluebird/bluebird-1.0.d.ts @@ -319,11 +319,9 @@ declare class Promise implements Promise.Thenable { * * Alias for `attempt();` for compatibility with earlier ECMAScript version. */ - static try(fn: () => Promise.Thenable, args?: any[], ctx?: any): Promise; - static try(fn: () => R, args?: any[], ctx?: any): Promise; + static try(fn: () => R|Promise.Thenable, args?: any[], ctx?: any): Promise; - static attempt(fn: () => Promise.Thenable, args?: any[], ctx?: any): Promise; - static attempt(fn: () => R, args?: any[], ctx?: any): Promise; + static attempt(fn: () => R|Promise.Thenable, args?: any[], ctx?: any): Promise; /** * Returns a new function that wraps the given function `fn`. The new function will always return a promise that is fulfilled with the original functions return values or rejected with thrown exceptions from the original function. diff --git a/bluebird/bluebird-tests.ts b/bluebird/bluebird-tests.ts index 00f6e951fa..7508e0b177 100644 --- a/bluebird/bluebird-tests.ts +++ b/bluebird/bluebird-tests.ts @@ -673,7 +673,16 @@ fooArrProm = fooArrProm.each((item: Foo, index: number, arrayLength: n // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +function getMaybePromise(): Foo|Promise { + return foo; +} +fooProm = Promise.try(() => { + return getMaybePromise(); +}); +fooProm = Promise.try(() => { + return getMaybePromise(); +}); fooProm = Promise.try(() => { return foo; }); @@ -698,6 +707,12 @@ fooProm = Promise.try(() => { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +fooProm = Promise.attempt(() => { + return getMaybePromise(); +}); +fooProm = Promise.attempt(() => { + return getMaybePromise(); +}); fooProm = Promise.attempt(() => { return foo; }); diff --git a/bluebird/bluebird.d.ts b/bluebird/bluebird.d.ts index 2dfdcf854f..b6a5dc6c1e 100644 --- a/bluebird/bluebird.d.ts +++ b/bluebird/bluebird.d.ts @@ -51,11 +51,9 @@ interface PromiseConstructor { * * Alias for `attempt();` for compatibility with earlier ECMAScript version. */ - try(fn: () => PromiseLike, args?: any[], ctx?: any): Promise; - try(fn: () => T, args?: any[], ctx?: any): Promise; + try(fn: () => T|PromiseLike, args?: any[], ctx?: any): Promise; - attempt(fn: () => PromiseLike, args?: any[], ctx?: any): Promise; - attempt(fn: () => T, args?: any[], ctx?: any): Promise; + attempt(fn: () => T|PromiseLike, args?: any[], ctx?: any): Promise; /** * Returns a new function that wraps the given function `fn`. The new function will always return a promise that is fulfilled with the original functions return values or rejected with thrown exceptions from the original function.