bluebird: fixed inference issue with try/attempt

This commit is contained in:
Brandon Furtwangler
2016-02-03 08:59:20 -08:00
parent e69fe60f2d
commit 9a579744d2
4 changed files with 34 additions and 8 deletions
+15
View File
@@ -504,7 +504,16 @@ fooArrProm = fooArrProm.filter<Foo>((item: Foo) => {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getMaybePromise(): Foo|Promise<Foo> {
return foo;
}
fooProm = Promise.try(() => {
return getMaybePromise();
});
fooProm = Promise.try<Foo>(() => {
return getMaybePromise();
});
fooProm = Promise.try(() => {
return foo;
});
@@ -529,6 +538,12 @@ fooProm = Promise.try(() => {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
fooProm = Promise.attempt(() => {
return getMaybePromise();
});
fooProm = Promise.attempt<Foo>(() => {
return getMaybePromise();
});
fooProm = Promise.attempt(() => {
return foo;
});
+2 -4
View File
@@ -319,11 +319,9 @@ declare class Promise<R> implements Promise.Thenable<R> {
*
* Alias for `attempt();` for compatibility with earlier ECMAScript version.
*/
static try<R>(fn: () => Promise.Thenable<R>, args?: any[], ctx?: any): Promise<R>;
static try<R>(fn: () => R, args?: any[], ctx?: any): Promise<R>;
static try<R>(fn: () => R|Promise.Thenable<R>, args?: any[], ctx?: any): Promise<R>;
static attempt<R>(fn: () => Promise.Thenable<R>, args?: any[], ctx?: any): Promise<R>;
static attempt<R>(fn: () => R, args?: any[], ctx?: any): Promise<R>;
static attempt<R>(fn: () => R|Promise.Thenable<R>, args?: any[], ctx?: any): Promise<R>;
/**
* 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.
+15
View File
@@ -673,7 +673,16 @@ fooArrProm = fooArrProm.each<Foo, Bar>((item: Foo, index: number, arrayLength: n
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getMaybePromise(): Foo|Promise<Foo> {
return foo;
}
fooProm = Promise.try(() => {
return getMaybePromise();
});
fooProm = Promise.try<Foo>(() => {
return getMaybePromise();
});
fooProm = Promise.try(() => {
return foo;
});
@@ -698,6 +707,12 @@ fooProm = Promise.try(() => {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
fooProm = Promise.attempt(() => {
return getMaybePromise();
});
fooProm = Promise.attempt<Foo>(() => {
return getMaybePromise();
});
fooProm = Promise.attempt(() => {
return foo;
});
+2 -4
View File
@@ -51,11 +51,9 @@ interface PromiseConstructor {
*
* Alias for `attempt();` for compatibility with earlier ECMAScript version.
*/
try<T>(fn: () => PromiseLike<T>, args?: any[], ctx?: any): Promise<T>;
try<T>(fn: () => T, args?: any[], ctx?: any): Promise<T>;
try<T>(fn: () => T|PromiseLike<T>, args?: any[], ctx?: any): Promise<T>;
attempt<T>(fn: () => PromiseLike<T>, args?: any[], ctx?: any): Promise<T>;
attempt<T>(fn: () => T, args?: any[], ctx?: any): Promise<T>;
attempt<T>(fn: () => T|PromiseLike<T>, args?: any[], ctx?: any): Promise<T>;
/**
* 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.