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..7979e8b6f 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 9244a9da3..a24cdfd7e 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; }); @@ -707,6 +716,12 @@ fooProm = Promise.try(() => { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +fooProm = Promise.attempt(() => { + return getMaybePromise(); +}); +fooProm = Promise.attempt(() => { + return getMaybePromise(); +}); fooProm = Promise.attempt(() => { return foo; });