mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 04:50:18 +00:00
bluebird: fixed inference issue with try/attempt
This commit is contained in:
@@ -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;
|
||||
});
|
||||
|
||||
Vendored
+2
-4
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
|
||||
Vendored
+2
-4
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user