From 9a579744d2cd8fc66ad0d1aa7319cd6a7e56cb2f Mon Sep 17 00:00:00 2001 From: Brandon Furtwangler Date: Wed, 3 Feb 2016 08:59:20 -0800 Subject: [PATCH 1/2] 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 f04317f6a..2aa795a4f 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 b8287e57c..2a43600d9 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 00f6e951f..7508e0b17 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 2dfdcf854..b6a5dc6c1 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. From dd328830dddffbe19e9addd7cf8532cbd3600816 Mon Sep 17 00:00:00 2001 From: Brandon Furtwangler Date: Mon, 8 Feb 2016 20:44:12 -0800 Subject: [PATCH 2/2] cleanup --- bluebird/bluebird-1.0.d.ts | 4 ++-- bluebird/bluebird.d.ts | 6 ------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/bluebird/bluebird-1.0.d.ts b/bluebird/bluebird-1.0.d.ts index 2a43600d9..7979e8b6f 100644 --- a/bluebird/bluebird-1.0.d.ts +++ b/bluebird/bluebird-1.0.d.ts @@ -319,9 +319,9 @@ declare class Promise implements Promise.Thenable { * * Alias for `attempt();` for compatibility with earlier ECMAScript version. */ - static try(fn: () => R|Promise.Thenable, args?: any[], ctx?: any): Promise; + static try(fn: () => R | Promise.Thenable, args?: any[], ctx?: any): Promise; - static attempt(fn: () => R|Promise.Thenable, 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.d.ts b/bluebird/bluebird.d.ts index a3cb98813..7a53d4e07 100644 --- a/bluebird/bluebird.d.ts +++ b/bluebird/bluebird.d.ts @@ -51,15 +51,9 @@ interface PromiseConstructor { * * Alias for `attempt();` for compatibility with earlier ECMAScript version. */ -<<<<<<< HEAD - try(fn: () => T|PromiseLike, args?: any[], ctx?: any): Promise; - - attempt(fn: () => T|PromiseLike, args?: any[], ctx?: any): Promise; -======= try(fn: () => T | PromiseLike, args?: any[], ctx?: any): Promise; attempt(fn: () => T | PromiseLike, args?: any[], ctx?: any): Promise; ->>>>>>> 72f0056f69f9a2290d2589c1a692896d24406928 /** * 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.