[Bluebird] Cleanup ignore lint error and Enable strintFunctionTypes and noImplicitThis (#20945)

* Cleanup part of lint error "no-unnecessary-generics"

* Cleanup lint error: adjacent-overload-signatures

* Arguments Array to Iterable(Bluebird not support ArrayLike)

* Delete already resolved TODO

* [WIP] cleanup lint-errors: void-return

* cleanup lint error: no-unnecessary-callback-wrapper

* cleanup ignore lint error: no-void-expression

* clean self

* Enable noImplicitThis

* Enable strictFunctionTypes

* Fix error dependent on tsc version(tsc version: 20171024)

* Cleanup lint error: void-return

* Apply https://github.com/DefinitelyTyped/DefinitelyTyped/pull/20945#discussion_r146791411
This commit is contained in:
segayuu
2017-10-26 03:17:24 +09:00
committed by Sheetal Nandi
parent 19f89399e4
commit df2f503d13
5 changed files with 339 additions and 302 deletions

View File

@@ -20,7 +20,6 @@ let exp: RegExp;
let anyArr: any[];
let strArr: string[];
let numArr: number[];
let voidVar: void;
// - - - - - - - - - - - - - - - - -
@@ -80,8 +79,7 @@ let voidProm: Promise<void>;
let fooProm: Promise<Foo>;
let barProm: Promise<Bar>;
let barOrVoidProm: Promise<Bar | void>;
let fooOrBarProm: Promise<Foo|Bar>;
let fooOrBarProm: Promise<Foo | Bar>;
let bazProm: Promise<Baz>;
// - - - - - - - - - - - - - - - - -
@@ -220,12 +218,14 @@ barProm = fooProm.then((value: Foo) => {
}, (reason: any) => {
return barProm;
});
barOrVoidProm = fooProm.then((value: Foo) => {
// $ExpectType Bluebird<void | Bar>
fooProm.then((value: Foo) => {
return bar;
}, (reason: any) => {
return;
});
barOrVoidProm = fooProm.then((value: Foo) => {
// $ExpectType Bluebird<void | Bar>
fooProm.then((value: Foo) => {
return bar;
}, (reason: any) => {
return voidProm;
@@ -241,43 +241,51 @@ barProm = barProm.then((value: Bar) => {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
fooProm = fooProm.catch((reason: any) => {
// $ExpectType Bluebird<void | Foo>
fooProm.catch((reason: any) => {
return;
});
fooProm = fooProm.caught((reason: any) => {
// $ExpectType Bluebird<void | Foo>
fooProm.caught((reason: any) => {
return;
});
fooProm = fooProm.catch((error: any) => {
// $ExpectType Bluebird<void | Foo>
fooProm.catch((error: any) => {
return true;
}, (reason: any) => {
return;
});
fooProm = fooProm.caught((error: any) => {
// $ExpectType Bluebird<void | Foo>
fooProm.caught((error: any) => {
return true;
}, (reason: any) => {
return;
});
fooProm = fooProm.catch((reason: any) => {
// $ExpectType Bluebird<void | Foo>
fooProm.catch((reason: any) => {
return voidProm;
});
fooProm = fooProm.caught((reason: any) => {
// $ExpectType Bluebird<void | Foo>
fooProm.caught((reason: any) => {
return voidProm;
});
fooProm = fooProm.catch((error: any) => {
// $ExpectType Bluebird<void | Foo>
fooProm.catch((error: any) => {
return true;
}, (reason: any) => {
return voidProm;
});
fooProm = fooProm.caught((error: any) => {
// $ExpectType Bluebird<void | Foo>
fooProm.caught((error: any) => {
return true;
}, (reason: any) => {
return voidProm;
});
fooProm = fooProm.catch((reason: any) => {
// $ExpectType Bluebird<void | Foo>
fooProm.catch<void | Foo>((reason: any) => { // tslint:disable-line:void-return
// handle multiple valid return types simultaneously
if (foo === null) {
return;
@@ -308,16 +316,20 @@ fooOrBarProm = fooProm.caught((error: any) => {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
fooProm = fooProm.catch(Error, (reason: any) => {
// $ExpectType Bluebird<void | Foo>
fooProm.catch(Error, (reason: any) => {
return;
});
fooProm = fooProm.catch(Promise.CancellationError, (reason: any) => {
// $ExpectType Bluebird<void | Foo>
fooProm.catch(Promise.CancellationError, (reason: any) => {
return;
});
fooProm = fooProm.caught(Error, (reason: any) => {
// $ExpectType Bluebird<void | Foo>
fooProm.caught(Error, (reason: any) => {
return;
});
fooProm = fooProm.caught(Promise.CancellationError, (reason: any) => {
// $ExpectType Bluebird<void | Foo>
fooProm.caught(Promise.CancellationError, (reason: any) => {
return;
});
@@ -339,61 +351,78 @@ fooOrBarProm = fooProm.caught(Promise.CancellationError, (reason: any) => {
class CustomError extends Error {
customField: number;
}
fooProm = fooProm.catch(CustomError, reason => {
// $ExpectType Bluebird<void | Foo>
fooProm.catch(CustomError, (reason: CustomError) => {
let a: number = reason.customField;
});
{
class CustomErrorWithConstructor extends Error {
constructor(public arg1: boolean, public arg2: number) {
super();
}
class CustomErrorWithConstructor extends Error {
arg1: boolean;
arg2: number;
constructor(arg1: boolean, arg2: number) {
super();
this.arg1 = arg1;
this.arg2 = arg2;
}
fooProm = fooProm.catch(CustomErrorWithConstructor, reason => {
let a: boolean = reason.arg1;
let b: number = reason.arg2;
});
}
// $ExpectType Bluebird<void | Foo>
fooProm.catch(CustomErrorWithConstructor, (reason: CustomErrorWithConstructor) => {
let a: boolean = reason.arg1;
let b: number = reason.arg2;
});
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{
class CustomError1 extends Error {}
class CustomError2 extends Error {}
class CustomError3 extends Error {}
class CustomError4 extends Error {}
class CustomError5 extends Error {}
class CustomError1 extends Error {}
class CustomError2 extends Error {}
class CustomError3 extends Error {}
class CustomError4 extends Error {}
class CustomError5 extends Error {}
fooProm = fooProm.catch(CustomError1, error => {});
fooProm = fooProm.catch(CustomError1, CustomError2, error => {});
fooProm = fooProm.catch(CustomError1, CustomError2, CustomError3, error => {});
fooProm = fooProm.catch(CustomError1, CustomError2, CustomError3, CustomError4, error => {});
fooProm = fooProm.catch(CustomError1, CustomError2, CustomError3, CustomError4, CustomError5, error => {});
// $ExpectType Bluebird<void | Foo>
fooProm.catch(CustomError1, error => {});
// $ExpectType Bluebird<void | Foo>
fooProm.catch(CustomError1, CustomError2, error => {});
// $ExpectType Bluebird<void | Foo>
fooProm.catch(CustomError1, CustomError2, CustomError3, error => {});
// $ExpectType Bluebird<void | Foo>
fooProm.catch(CustomError1, CustomError2, CustomError3, CustomError4, error => {});
// $ExpectType Bluebird<void | Foo>
fooProm.catch(CustomError1, CustomError2, CustomError3, CustomError4, CustomError5, error => {});
const booPredicate1 = (error: CustomError1) => true;
const booPredicate2 = (error: [number]) => true;
const booPredicate3 = (error: string) => true;
const booPredicate4 = (error: object) => true;
const booPredicate5 = (error: any) => true;
const booPredicate1 = (error: CustomError1) => true;
const booPredicate2 = (error: [number]) => true;
const booPredicate3 = (error: string) => true;
const booPredicate4 = (error: object) => true;
const booPredicate5 = (error: any) => true;
fooProm = fooProm.catch(booPredicate1, error => {});
fooProm = fooProm.catch(booPredicate1, booPredicate2, error => {});
fooProm = fooProm.catch(booPredicate1, booPredicate2, booPredicate3, error => {});
fooProm = fooProm.catch(booPredicate1, booPredicate2, booPredicate3, booPredicate4, error => {});
fooProm = fooProm.catch(booPredicate1, booPredicate2, booPredicate3, booPredicate4, booPredicate5, error => {});
// $ExpectType Bluebird<void | Foo>
fooProm.catch(booPredicate1, error => {});
// $ExpectType Bluebird<void | Foo>
fooProm.catch(booPredicate1, booPredicate2, error => {});
// $ExpectType Bluebird<void | Foo>
fooProm.catch(booPredicate1, booPredicate2, booPredicate3, error => {});
// $ExpectType Bluebird<void | Foo>
fooProm.catch(booPredicate1, booPredicate2, booPredicate3, booPredicate4, error => {});
// $ExpectType Bluebird<void | Foo>
fooProm.catch(booPredicate1, booPredicate2, booPredicate3, booPredicate4, booPredicate5, error => {});
const booObject1 = new CustomError1();
const booObject2 = [400, 500];
const booObject3 = ["Error1", "Error2"];
const booObject4 = {code: 400};
const booObject5: any = null;
const booObject1 = new CustomError1();
const booObject2 = [400, 500];
const booObject3 = ["Error1", "Error2"];
const booObject4 = {code: 400};
const booObject5: any = null;
fooProm = fooProm.catch(booObject1, error => {});
fooProm = fooProm.catch(booObject1, booObject2, error => {});
fooProm = fooProm.catch(booObject1, booObject2, booObject3, error => {});
fooProm = fooProm.catch(booObject1, booObject2, booObject3, booObject4, error => {});
fooProm = fooProm.catch(booObject1, booObject2, booObject3, booObject4, booObject5, error => {});
}
// $ExpectType Bluebird<void | Foo>
fooProm.catch(booObject1, error => {});
// $ExpectType Bluebird<void | Foo>
fooProm.catch(booObject1, booObject2, error => {});
// $ExpectType Bluebird<void | Foo>
fooProm.catch(booObject1, booObject2, booObject3, error => {});
// $ExpectType Bluebird<void | Foo>
fooProm.catch(booObject1, booObject2, booObject3, booObject4, error => {});
// $ExpectType Bluebird<void | Foo>
fooProm.catch(booObject1, booObject2, booObject3, booObject4, booObject5, error => {});
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -433,23 +462,27 @@ fooProm = fooProm.bind(obj);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
voidVar = fooProm.done((value: Foo) => {
// $ExpectType void
fooProm.done((value: Foo) => {
return bar;
}, (reason: any) => {
return bar;
});
voidVar = fooProm.done((value: Foo) => {
// $ExpectType void
fooProm.done((value: Foo) => {
return bar;
});
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
voidVar = fooProm.done((value: Foo) => {
// $ExpectType void
fooProm.done((value: Foo) => {
return barThen;
}, (reason: any) => {
return barThen;
});
voidVar = fooProm.done((value: Foo) => {
// $ExpectType void
fooProm.done((value: Foo) => {
return barThen;
});
@@ -508,7 +541,8 @@ fooProm = fooProm.nodeify((err: any, foo?: Foo) => { }, { spread: true });
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
voidVar = fooProm.cancel();
// $ExpectType void
fooProm.cancel();
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -520,11 +554,10 @@ bool = fooProm.isResolved();
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
anyProm = fooProm.call(str);
anyProm = fooProm.call(str, 1, 2, 3);
anyProm = fooProm.call("foo");
anyProm = fooProm.call("foo", 1, 2, 3);
// TODO enable get() test when implemented
// barProm = fooProm.get(str);
voidProm = fooProm.get("foo").then((method) => { str = method(); });
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -542,7 +575,7 @@ fooProm = fooProm.thenThrow(err);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
barProm = fooProm.catchReturn(bar);
fooOrBarProm = fooProm.return(foo).catchReturn(bar);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -790,15 +823,15 @@ asyncfunc = Promise.promisify(f);
asyncfunc = Promise.promisify(f, obj);
obj = Promise.promisifyAll(obj);
anyProm = Promise.fromNode(callback => nodeCallbackFunc(callback));
anyProm = Promise.fromNode(callback => nodeCallbackFuncErrorOnly(callback));
anyProm = Promise.fromNode(callback => nodeCallbackFunc(callback), {multiArgs : true});
anyProm = Promise.fromNode(callback => nodeCallbackFuncErrorOnly(callback), {multiArgs : true});
anyProm = Promise.fromNode(nodeCallbackFunc);
anyProm = Promise.fromNode(nodeCallbackFuncErrorOnly);
anyProm = Promise.fromNode(nodeCallbackFunc, {multiArgs : true});
anyProm = Promise.fromNode(nodeCallbackFuncErrorOnly, {multiArgs : true});
anyProm = Promise.fromCallback(callback => nodeCallbackFunc(callback));
anyProm = Promise.fromCallback(callback => nodeCallbackFuncErrorOnly(callback));
anyProm = Promise.fromCallback(callback => nodeCallbackFunc(callback), {multiArgs : true});
anyProm = Promise.fromCallback(callback => nodeCallbackFuncErrorOnly(callback), {multiArgs : true});
anyProm = Promise.fromCallback(nodeCallbackFunc);
anyProm = Promise.fromCallback(nodeCallbackFuncErrorOnly);
anyProm = Promise.fromCallback(nodeCallbackFunc, {multiArgs : true});
anyProm = Promise.fromCallback(nodeCallbackFuncErrorOnly, {multiArgs : true});
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -812,14 +845,11 @@ function defaultFilter(name: string, func: (...args: any[]) => any) {
function DOMPromisifier(originalMethod: (...args: any[]) => any) {
// return a function
return function promisified() {
let args = [].slice.call(arguments);
// Needed so that the original method can be called with the correct receiver
let self = this;
return function promisified(this: object, ...args: any[]) {
// which returns a promise
return new Promise((resolve, reject) => {
args.push(resolve, reject);
originalMethod.apply(self, args);
originalMethod.apply(this, args);
});
};
}

View File

@@ -47,17 +47,15 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
*/
// Based on PromiseLike.then, but returns a Bluebird instance.
then<U>(onFulfill?: (value: R) => U | PromiseLike<U>, onReject?: (error: any) => U | PromiseLike<U>): Bluebird<U>; // For simpler signature help.
then<TResult1 = R, TResult2 = never>(onfulfilled?: ((value: R) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Bluebird<TResult1 | TResult2>;
then<TResult1 = R, TResult2 = never>(onfulfilled?: ((value: R) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Bluebird<TResult1 | TResult2>;
/**
* This is a catch-all exception handler, shortcut for calling `.then(null, handler)` on this promise. Any exception happening in a `.then`-chain will propagate to nearest `.catch` handler.
*
* Alias `.caught();` for compatibility with earlier ECMAScript version.
*/
catch(onReject?: (error: any) => R | PromiseLike<R> | void | PromiseLike<void>): Bluebird<R>;
caught(onReject?: (error: any) => R | PromiseLike<R> | void | PromiseLike<void>): Bluebird<R>;
catch<U>(onReject?: (error: any) => U | PromiseLike<U>): Bluebird<U | R>;
caught<U>(onReject?: (error: any) => U | PromiseLike<U>): Bluebird<U | R>;
catch(onReject: (error: any) => R | PromiseLike<R>): Bluebird<R>;
catch<U>(onReject?: ((error: any) => U | PromiseLike<U>) | undefined | null): Bluebird<U | R>;
/**
* This extends `.catch` to work more like catch-clauses in languages like Java or C#. Instead of manually checking `instanceof` or `.name === "SomeError"`, you may specify a number of error constructors which are eligible for this catch handler. The catch handler that is first met that has eligible constructors specified, is the one that will be called.
@@ -65,8 +63,6 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
* This method also supports predicate-based filters. If you pass a predicate function instead of an error constructor, the predicate will receive the error as an argument. The return result of the predicate will be used determine whether the error handler should be called.
*
* Alias `.caught();` for compatibility with earlier ECMAScript version.
*
* TODO: disallow non-objects
*/
catch<E1 extends Error, E2 extends Error, E3 extends Error, E4 extends Error, E5 extends Error>(
filter1: (new (...args: any[]) => E1),
@@ -74,7 +70,7 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
filter3: (new (...args: any[]) => E3),
filter4: (new (...args: any[]) => E4),
filter5: (new (...args: any[]) => E5),
onReject: (error: E1 | E2 | E3 | E4 | E5) => R | PromiseLike<R> | void | PromiseLike<void>,
onReject: (error: E1 | E2 | E3 | E4 | E5) => R | PromiseLike<R>,
): Bluebird<R>;
catch<E1, E2, E3, E4, E5>(
filter1: ((error: E1) => boolean) | (E1 & object),
@@ -82,23 +78,7 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
filter3: ((error: E3) => boolean) | (E3 & object),
filter4: ((error: E4) => boolean) | (E4 & object),
filter5: ((error: E5) => boolean) | (E5 & object),
onReject: (error: E1 | E2 | E3 | E4 | E5) => R | PromiseLike<R> | void | PromiseLike<void>,
): Bluebird<R>;
caught<E1 extends Error, E2 extends Error, E3 extends Error, E4 extends Error, E5 extends Error>(
filter1: (new (...args: any[]) => E1),
filter2: (new (...args: any[]) => E2),
filter3: (new (...args: any[]) => E3),
filter4: (new (...args: any[]) => E4),
filter5: (new (...args: any[]) => E5),
onReject: (error: E1 | E2 | E3 | E4 | E5) => R | PromiseLike<R> | void | PromiseLike<void>,
): Bluebird<R>;
caught<E1, E2, E3, E4, E5>(
filter1: ((error: E1) => boolean) | (E1 & object),
filter2: ((error: E2) => boolean) | (E2 & object),
filter3: ((error: E3) => boolean) | (E3 & object),
filter4: ((error: E4) => boolean) | (E4 & object),
filter5: ((error: E5) => boolean) | (E5 & object),
onReject: (error: E1 | E2 | E3 | E4 | E5) => R | PromiseLike<R> | void | PromiseLike<void>,
onReject: (error: E1 | E2 | E3 | E4 | E5) => R | PromiseLike<R>,
): Bluebird<R>;
catch<U, E1 extends Error, E2 extends Error, E3 extends Error, E4 extends Error, E5 extends Error>(
filter1: (new (...args: any[]) => E1),
@@ -106,7 +86,7 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
filter3: (new (...args: any[]) => E3),
filter4: (new (...args: any[]) => E4),
filter5: (new (...args: any[]) => E5),
onReject: (error: E1 | E2 | E3 | E4 | E5) => U | PromiseLike<U> | void | PromiseLike<void>,
onReject: (error: E1 | E2 | E3 | E4 | E5) => U | PromiseLike<U>,
): Bluebird<U | R>;
catch<U, E1, E2, E3, E4, E5>(
filter1: ((error: E1) => boolean) | (E1 & object),
@@ -116,6 +96,130 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
filter5: ((error: E5) => boolean) | (E5 & object),
onReject: (error: E1 | E2 | E3 | E4 | E5) => U | PromiseLike<U>,
): Bluebird<U | R>;
catch<E1 extends Error, E2 extends Error, E3 extends Error, E4 extends Error>(
filter1: (new (...args: any[]) => E1),
filter2: (new (...args: any[]) => E2),
filter3: (new (...args: any[]) => E3),
filter4: (new (...args: any[]) => E4),
onReject: (error: E1 | E2 | E3 | E4) => R | PromiseLike<R>,
): Bluebird<R>;
catch<E1, E2, E3, E4>(
filter1: ((error: E1) => boolean) | (E1 & object),
filter2: ((error: E2) => boolean) | (E2 & object),
filter3: ((error: E3) => boolean) | (E3 & object),
filter4: ((error: E4) => boolean) | (E4 & object),
onReject: (error: E1 | E2 | E3 | E4) => R | PromiseLike<R>,
): Bluebird<R>;
catch<U, E1 extends Error, E2 extends Error, E3 extends Error, E4 extends Error>(
filter1: (new (...args: any[]) => E1),
filter2: (new (...args: any[]) => E2),
filter3: (new (...args: any[]) => E3),
filter4: (new (...args: any[]) => E4),
onReject: (error: E1 | E2 | E3 | E4) => U | PromiseLike<U>,
): Bluebird<U | R>;
catch<U, E1, E2, E3, E4>(
filter1: ((error: E1) => boolean) | (E1 & object),
filter2: ((error: E2) => boolean) | (E2 & object),
filter3: ((error: E3) => boolean) | (E3 & object),
filter4: ((error: E4) => boolean) | (E4 & object),
onReject: (error: E1 | E2 | E3 | E4) => U | PromiseLike<U>,
): Bluebird<U | R>;
catch<E1 extends Error, E2 extends Error, E3 extends Error>(
filter1: (new (...args: any[]) => E1),
filter2: (new (...args: any[]) => E2),
filter3: (new (...args: any[]) => E3),
onReject: (error: E1 | E2 | E3) => R | PromiseLike<R>,
): Bluebird<R>;
catch<E1, E2, E3>(
filter1: ((error: E1) => boolean) | (E1 & object),
filter2: ((error: E2) => boolean) | (E2 & object),
filter3: ((error: E3) => boolean) | (E3 & object),
onReject: (error: E1 | E2 | E3) => R | PromiseLike<R>,
): Bluebird<R>;
catch<U, E1 extends Error, E2 extends Error, E3 extends Error>(
filter1: (new (...args: any[]) => E1),
filter2: (new (...args: any[]) => E2),
filter3: (new (...args: any[]) => E3),
onReject: (error: E1 | E2 | E3) => U | PromiseLike<U>,
): Bluebird<U | R>;
catch<U, E1, E2, E3>(
filter1: ((error: E1) => boolean) | (E1 & object),
filter2: ((error: E2) => boolean) | (E2 & object),
filter3: ((error: E3) => boolean) | (E3 & object),
onReject: (error: E1 | E2 | E3) => U | PromiseLike<U>,
): Bluebird<U | R>;
catch<E1 extends Error, E2 extends Error>(
filter1: (new (...args: any[]) => E1),
filter2: (new (...args: any[]) => E2),
onReject: (error: E1 | E2) => R | PromiseLike<R>,
): Bluebird<R>;
catch<E1, E2>(
filter1: ((error: E1) => boolean) | (E1 & object),
filter2: ((error: E2) => boolean) | (E2 & object),
onReject: (error: E1 | E2) => R | PromiseLike<R>,
): Bluebird<R>;
catch<U, E1 extends Error, E2 extends Error>(
filter1: (new (...args: any[]) => E1),
filter2: (new (...args: any[]) => E2),
onReject: (error: E1 | E2) => U | PromiseLike<U>,
): Bluebird<U | R>;
catch<U, E1, E2>(
filter1: ((error: E1) => boolean) | (E1 & object),
filter2: ((error: E2) => boolean) | (E2 & object),
onReject: (error: E1 | E2) => U | PromiseLike<U>,
): Bluebird<U | R>;
catch<E1 extends Error>(
filter1: (new (...args: any[]) => E1),
onReject: (error: E1) => R | PromiseLike<R>,
): Bluebird<R>;
catch<E1>(
filter1: ((error: E1) => boolean) | (E1 & object),
onReject: (error: E1) => R | PromiseLike<R>,
): Bluebird<R>;
catch<U, E1 extends Error>(
filter1: (new (...args: any[]) => E1),
onReject: (error: E1) => U | PromiseLike<U>,
): Bluebird<U | R>;
catch<U, E1>(
filter1: ((error: E1) => boolean) | (E1 & object),
onReject: (error: E1) => U | PromiseLike<U>,
): Bluebird<U | R>;
/**
* This is a catch-all exception handler, shortcut for calling `.then(null, handler)` on this promise. Any exception happening in a `.then`-chain will propagate to nearest `.catch` handler.
*
* Alias `.caught();` for compatibility with earlier ECMAScript version.
*/
caught(onReject: (error: any) => R | PromiseLike<R>): Bluebird<R>;
caught<U>(onReject?: ((error: any) => U | PromiseLike<U>) | undefined | null): Bluebird<U | R>;
/**
* This extends `.catch` to work more like catch-clauses in languages like Java or C#. Instead of manually checking `instanceof` or `.name === "SomeError"`, you may specify a number of error constructors which are eligible for this catch handler. The catch handler that is first met that has eligible constructors specified, is the one that will be called.
*
* This method also supports predicate-based filters. If you pass a predicate function instead of an error constructor, the predicate will receive the error as an argument. The return result of the predicate will be used determine whether the error handler should be called.
*
* Alias `.caught();` for compatibility with earlier ECMAScript version.
*/
caught<E1 extends Error, E2 extends Error, E3 extends Error, E4 extends Error, E5 extends Error>(
filter1: (new (...args: any[]) => E1),
filter2: (new (...args: any[]) => E2),
filter3: (new (...args: any[]) => E3),
filter4: (new (...args: any[]) => E4),
filter5: (new (...args: any[]) => E5),
onReject: (error: E1 | E2 | E3 | E4 | E5) => R | PromiseLike<R>,
): Bluebird<R>;
caught<E1, E2, E3, E4, E5>(
filter1: ((error: E1) => boolean) | (E1 & object),
filter2: ((error: E2) => boolean) | (E2 & object),
filter3: ((error: E3) => boolean) | (E3 & object),
filter4: ((error: E4) => boolean) | (E4 & object),
filter5: ((error: E5) => boolean) | (E5 & object),
onReject: (error: E1 | E2 | E3 | E4 | E5) => R | PromiseLike<R>,
): Bluebird<R>;
caught<U, E1 extends Error, E2 extends Error, E3 extends Error, E4 extends Error, E5 extends Error>(
filter1: (new (...args: any[]) => E1),
filter2: (new (...args: any[]) => E2),
@@ -133,48 +237,20 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
onReject: (error: E1 | E2 | E3 | E4 | E5) => U | PromiseLike<U>,
): Bluebird<U | R>;
catch<E1 extends Error, E2 extends Error, E3 extends Error, E4 extends Error>(
filter1: (new (...args: any[]) => E1),
filter2: (new (...args: any[]) => E2),
filter3: (new (...args: any[]) => E3),
filter4: (new (...args: any[]) => E4),
onReject: (error: E1 | E2 | E3 | E4) => R | PromiseLike<R> | void | PromiseLike<void>,
): Bluebird<R>;
catch<E1, E2, E3, E4>(
filter1: ((error: E1) => boolean) | (E1 & object),
filter2: ((error: E2) => boolean) | (E2 & object),
filter3: ((error: E3) => boolean) | (E3 & object),
filter4: ((error: E4) => boolean) | (E4 & object),
onReject: (error: E1 | E2 | E3 | E4) => R | PromiseLike<R> | void | PromiseLike<void>,
): Bluebird<R>;
caught<E1 extends Error, E2 extends Error, E3 extends Error, E4 extends Error>(
filter1: (new (...args: any[]) => E1),
filter2: (new (...args: any[]) => E2),
filter3: (new (...args: any[]) => E3),
filter4: (new (...args: any[]) => E4),
onReject: (error: E1 | E2 | E3 | E4) => R | PromiseLike<R> | void | PromiseLike<void>,
onReject: (error: E1 | E2 | E3 | E4) => R | PromiseLike<R>,
): Bluebird<R>;
caught<E1, E2, E3, E4>(
filter1: ((error: E1) => boolean) | (E1 & object),
filter2: ((error: E2) => boolean) | (E2 & object),
filter3: ((error: E3) => boolean) | (E3 & object),
filter4: ((error: E4) => boolean) | (E4 & object),
onReject: (error: E1 | E2 | E3 | E4) => R | PromiseLike<R> | void | PromiseLike<void>,
onReject: (error: E1 | E2 | E3 | E4) => R | PromiseLike<R>,
): Bluebird<R>;
catch<U, E1 extends Error, E2 extends Error, E3 extends Error, E4 extends Error>(
filter1: (new (...args: any[]) => E1),
filter2: (new (...args: any[]) => E2),
filter3: (new (...args: any[]) => E3),
filter4: (new (...args: any[]) => E4),
onReject: (error: E1 | E2 | E3 | E4) => U | PromiseLike<U>,
): Bluebird<U | R>;
catch<U, E1, E2, E3, E4>(
filter1: ((error: E1) => boolean) | (E1 & object),
filter2: ((error: E2) => boolean) | (E2 & object),
filter3: ((error: E3) => boolean) | (E3 & object),
filter4: ((error: E4) => boolean) | (E4 & object),
onReject: (error: E1 | E2 | E3 | E4) => U | PromiseLike<U>,
): Bluebird<U | R>;
caught<U, E1 extends Error, E2 extends Error, E3 extends Error, E4 extends Error>(
filter1: (new (...args: any[]) => E1),
filter2: (new (...args: any[]) => E2),
@@ -190,42 +266,18 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
onReject: (error: E1 | E2 | E3 | E4) => U | PromiseLike<U>,
): Bluebird<U | R>;
catch<E1 extends Error, E2 extends Error, E3 extends Error>(
filter1: (new (...args: any[]) => E1),
filter2: (new (...args: any[]) => E2),
filter3: (new (...args: any[]) => E3),
onReject: (error: E1 | E2 | E3) => R | PromiseLike<R> | void | PromiseLike<void>,
): Bluebird<R>;
catch<E1, E2, E3>(
filter1: ((error: E1) => boolean) | (E1 & object),
filter2: ((error: E2) => boolean) | (E2 & object),
filter3: ((error: E3) => boolean) | (E3 & object),
onReject: (error: E1 | E2 | E3) => R | PromiseLike<R> | void | PromiseLike<void>,
): Bluebird<R>;
caught<E1 extends Error, E2 extends Error, E3 extends Error>(
filter1: (new (...args: any[]) => E1),
filter2: (new (...args: any[]) => E2),
filter3: (new (...args: any[]) => E3),
onReject: (error: E1 | E2 | E3) => R | PromiseLike<R> | void | PromiseLike<void>,
onReject: (error: E1 | E2 | E3) => R | PromiseLike<R>,
): Bluebird<R>;
caught<E1, E2, E3>(
filter1: ((error: E1) => boolean) | (E1 & object),
filter2: ((error: E2) => boolean) | (E2 & object),
filter3: ((error: E3) => boolean) | (E3 & object),
onReject: (error: E1 | E2 | E3) => R | PromiseLike<R> | void | PromiseLike<void>,
onReject: (error: E1 | E2 | E3) => R | PromiseLike<R>,
): Bluebird<R>;
catch<U, E1 extends Error, E2 extends Error, E3 extends Error>(
filter1: (new (...args: any[]) => E1),
filter2: (new (...args: any[]) => E2),
filter3: (new (...args: any[]) => E3),
onReject: (error: E1 | E2 | E3) => U | PromiseLike<U>,
): Bluebird<U | R>;
catch<U, E1, E2, E3>(
filter1: ((error: E1) => boolean) | (E1 & object),
filter2: ((error: E2) => boolean) | (E2 & object),
filter3: ((error: E3) => boolean) | (E3 & object),
onReject: (error: E1 | E2 | E3) => U | PromiseLike<U>,
): Bluebird<U | R>;
caught<U, E1 extends Error, E2 extends Error, E3 extends Error>(
filter1: (new (...args: any[]) => E1),
filter2: (new (...args: any[]) => E2),
@@ -239,36 +291,16 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
onReject: (error: E1 | E2 | E3) => U | PromiseLike<U>,
): Bluebird<U | R>;
catch<E1 extends Error, E2 extends Error>(
filter1: (new (...args: any[]) => E1),
filter2: (new (...args: any[]) => E2),
onReject: (error: E1 | E2) => R | PromiseLike<R> | void | PromiseLike<void>,
): Bluebird<R>;
catch<E1, E2>(
filter1: ((error: E1) => boolean) | (E1 & object),
filter2: ((error: E2) => boolean) | (E2 & object),
onReject: (error: E1 | E2) => R | PromiseLike<R> | void | PromiseLike<void>,
): Bluebird<R>;
caught<E1 extends Error, E2 extends Error>(
filter1: (new (...args: any[]) => E1),
filter2: (new (...args: any[]) => E2),
onReject: (error: E1 | E2) => R | PromiseLike<R> | void | PromiseLike<void>,
onReject: (error: E1 | E2) => R | PromiseLike<R>,
): Bluebird<R>;
caught<E1, E2>(
filter1: ((error: E1) => boolean) | (E1 & object),
filter2: ((error: E2) => boolean) | (E2 & object),
onReject: (error: E1 | E2) => R | PromiseLike<R> | void | PromiseLike<void>,
onReject: (error: E1 | E2) => R | PromiseLike<R>,
): Bluebird<R>;
catch<U, E1 extends Error, E2 extends Error>(
filter1: (new (...args: any[]) => E1),
filter2: (new (...args: any[]) => E2),
onReject: (error: E1 | E2) => U | PromiseLike<U>,
): Bluebird<U | R>;
catch<U, E1, E2>(
filter1: ((error: E1) => boolean) | (E1 & object),
filter2: ((error: E2) => boolean) | (E2 & object),
onReject: (error: E1 | E2) => U | PromiseLike<U>,
): Bluebird<U | R>;
caught<U, E1 extends Error, E2 extends Error>(
filter1: (new (...args: any[]) => E1),
filter2: (new (...args: any[]) => E2),
@@ -280,30 +312,14 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
onReject: (error: E1 | E2) => U | PromiseLike<U>,
): Bluebird<U | R>;
catch<E1 extends Error>(
filter1: (new (...args: any[]) => E1),
onReject: (error: E1) => R | PromiseLike<R> | void | PromiseLike<void>,
): Bluebird<R>;
catch<E1>(
filter1: ((error: E1) => boolean) | (E1 & object),
onReject: (error: E1) => R | PromiseLike<R> | void | PromiseLike<void>,
): Bluebird<R>;
caught<E1 extends Error>(
filter1: (new (...args: any[]) => E1),
onReject: (error: E1) => R | PromiseLike<R> | void | PromiseLike<void>,
onReject: (error: E1) => R | PromiseLike<R>,
): Bluebird<R>;
caught<E1>(
filter1: ((error: E1) => boolean) | (E1 & object),
onReject: (error: E1) => R | PromiseLike<R> | void | PromiseLike<void>,
onReject: (error: E1) => R | PromiseLike<R>,
): Bluebird<R>;
catch<U, E1 extends Error>(
filter1: (new (...args: any[]) => E1),
onReject: (error: E1) => U | PromiseLike<U>,
): Bluebird<U | R>;
catch<U, E1>(
filter1: ((error: E1) => boolean) | (E1 & object),
onReject: (error: E1) => U | PromiseLike<U>,
): Bluebird<U | R>;
caught<U, E1 extends Error>(
filter1: (new (...args: any[]) => E1),
onReject: (error: E1) => U | PromiseLike<U>,
@@ -344,7 +360,6 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
/**
* Like `.catch()` but rethrows the error
* TODO: disallow non-objects
*/
tapCatch<U>(onReject: (error?: any) => U | PromiseLike<U>): Bluebird<R>;
@@ -457,7 +472,7 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
* });
* </code>
*/
call(propertyName: string, ...args: any[]): Bluebird<any>;
call(propertyName: keyof R, ...args: any[]): Bluebird<any>;
/**
* This is a convenience method for doing:
@@ -468,9 +483,7 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
* });
* </code>
*/
// TODO: Use "type property type" once it's there
// @see https://github.com/Microsoft/TypeScript/issues/1295
get<U>(key: string | number): Bluebird<U>;
get<U extends keyof R>(key: U): Bluebird<R[U]>;
/**
* Convenience method for:
@@ -486,8 +499,8 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
* Alias `.thenReturn();` for compatibility with earlier ECMAScript version.
*/
return(): Bluebird<void>;
thenReturn(): Bluebird<void>;
return<U>(value: U): Bluebird<U>;
thenReturn(): Bluebird<void>;
thenReturn<U>(value: U): Bluebird<U>;
/**
@@ -502,8 +515,8 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
*
* Alias `.thenThrow();` for compatibility with earlier ECMAScript version.
*/
throw(reason: Error): Bluebird<R>;
thenThrow(reason: Error): Bluebird<R>;
throw(reason: Error): Bluebird<never>;
thenThrow(reason: Error): Bluebird<never>;
/**
* Convenience method for:
@@ -515,40 +528,39 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
* </code>
*
* in the case where `value` doesn't change its value. That means `value` is bound at the time of calling `.catchReturn()`
* TODO: disallow non-objects
*/
catchReturn<U>(value: U): Bluebird<U>;
catchReturn<U>(value: U): Bluebird<R | U>;
catchReturn<U, E1 extends Error, E2 extends Error, E3 extends Error, E4 extends Error, E5 extends Error>(
filter1: (new (...args: any[]) => E1) | ((error: any) => boolean) | object,
filter2: (new (...args: any[]) => E2) | ((error: any) => boolean) | object,
filter3: (new (...args: any[]) => E3) | ((error: any) => boolean) | object,
filter4: (new (...args: any[]) => E4) | ((error: any) => boolean) | object,
filter5: (new (...args: any[]) => E5) | ((error: any) => boolean) | object,
catchReturn<U>(
filter1: (new (...args: any[]) => Error) | ((error: any) => boolean) | object,
filter2: (new (...args: any[]) => Error) | ((error: any) => boolean) | object,
filter3: (new (...args: any[]) => Error) | ((error: any) => boolean) | object,
filter4: (new (...args: any[]) => Error) | ((error: any) => boolean) | object,
filter5: (new (...args: any[]) => Error) | ((error: any) => boolean) | object,
value: U,
): Bluebird<U>;
catchReturn<U, E1 extends Error, E2 extends Error, E3 extends Error, E4 extends Error>(
filter1: (new (...args: any[]) => E1) | ((error: any) => boolean) | object,
filter2: (new (...args: any[]) => E2) | ((error: any) => boolean) | object,
filter3: (new (...args: any[]) => E3) | ((error: any) => boolean) | object,
filter4: (new (...args: any[]) => E4) | ((error: any) => boolean) | object,
): Bluebird<R | U>;
catchReturn<U>(
filter1: (new (...args: any[]) => Error) | ((error: any) => boolean) | object,
filter2: (new (...args: any[]) => Error) | ((error: any) => boolean) | object,
filter3: (new (...args: any[]) => Error) | ((error: any) => boolean) | object,
filter4: (new (...args: any[]) => Error) | ((error: any) => boolean) | object,
value: U,
): Bluebird<U>;
catchReturn<U, E1 extends Error, E2 extends Error, E3 extends Error>(
filter1: (new (...args: any[]) => E1) | ((error: any) => boolean) | object,
filter2: (new (...args: any[]) => E2) | ((error: any) => boolean) | object,
filter3: (new (...args: any[]) => E3) | ((error: any) => boolean) | object,
): Bluebird<R | U>;
catchReturn<U>(
filter1: (new (...args: any[]) => Error) | ((error: any) => boolean) | object,
filter2: (new (...args: any[]) => Error) | ((error: any) => boolean) | object,
filter3: (new (...args: any[]) => Error) | ((error: any) => boolean) | object,
value: U,
): Bluebird<U>;
catchReturn<U, E1 extends Error, E2 extends Error>(
filter1: (new (...args: any[]) => E1) | ((error: any) => boolean) | object,
filter2: (new (...args: any[]) => E2) | ((error: any) => boolean) | object,
): Bluebird<R | U>;
catchReturn<U>(
filter1: (new (...args: any[]) => Error) | ((error: any) => boolean) | object,
filter2: (new (...args: any[]) => Error) | ((error: any) => boolean) | object,
value: U,
): Bluebird<U>;
catchReturn<U, E1 extends Error>(
filter1: (new (...args: any[]) => E1) | ((error: any) => boolean) | object,
): Bluebird<R | U>;
catchReturn<U>(
filter1: (new (...args: any[]) => Error) | ((error: any) => boolean) | object,
value: U,
): Bluebird<U>;
): Bluebird<R | U>;
/**
* Convenience method for:
@@ -559,38 +571,37 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
* });
* </code>
* Same limitations apply as with `.catchReturn()`.
* TODO: disallow non-objects
*/
catchThrow(reason: Error): Bluebird<R>;
catchThrow<E1 extends Error, E2 extends Error, E3 extends Error, E4 extends Error, E5 extends Error>(
filter1: (new (...args: any[]) => E1) | ((error: any) => boolean) | object,
filter2: (new (...args: any[]) => E2) | ((error: any) => boolean) | object,
filter3: (new (...args: any[]) => E3) | ((error: any) => boolean) | object,
filter4: (new (...args: any[]) => E4) | ((error: any) => boolean) | object,
filter5: (new (...args: any[]) => E5) | ((error: any) => boolean) | object,
catchThrow(
filter1: (new (...args: any[]) => Error) | ((error: any) => boolean) | object,
filter2: (new (...args: any[]) => Error) | ((error: any) => boolean) | object,
filter3: (new (...args: any[]) => Error) | ((error: any) => boolean) | object,
filter4: (new (...args: any[]) => Error) | ((error: any) => boolean) | object,
filter5: (new (...args: any[]) => Error) | ((error: any) => boolean) | object,
reason: Error,
): Bluebird<R>;
catchThrow<E1 extends Error, E2 extends Error, E3 extends Error, E4 extends Error>(
filter1: (new (...args: any[]) => E1) | ((error: any) => boolean) | object,
filter2: (new (...args: any[]) => E2) | ((error: any) => boolean) | object,
filter3: (new (...args: any[]) => E3) | ((error: any) => boolean) | object,
filter4: (new (...args: any[]) => E4) | ((error: any) => boolean) | object,
catchThrow(
filter1: (new (...args: any[]) => Error) | ((error: any) => boolean) | object,
filter2: (new (...args: any[]) => Error) | ((error: any) => boolean) | object,
filter3: (new (...args: any[]) => Error) | ((error: any) => boolean) | object,
filter4: (new (...args: any[]) => Error) | ((error: any) => boolean) | object,
reason: Error,
): Bluebird<R>;
catchThrow<E1 extends Error, E2 extends Error, E3 extends Error>(
filter1: (new (...args: any[]) => E1) | ((error: any) => boolean) | object,
filter2: (new (...args: any[]) => E2) | ((error: any) => boolean) | object,
filter3: (new (...args: any[]) => E3) | ((error: any) => boolean) | object,
catchThrow(
filter1: (new (...args: any[]) => Error) | ((error: any) => boolean) | object,
filter2: (new (...args: any[]) => Error) | ((error: any) => boolean) | object,
filter3: (new (...args: any[]) => Error) | ((error: any) => boolean) | object,
reason: Error,
): Bluebird<R>;
catchThrow<E1 extends Error, E2 extends Error>(
filter1: (new (...args: any[]) => E1) | ((error: any) => boolean) | object,
filter2: (new (...args: any[]) => E2) | ((error: any) => boolean) | object,
catchThrow(
filter1: (new (...args: any[]) => Error) | ((error: any) => boolean) | object,
filter2: (new (...args: any[]) => Error) | ((error: any) => boolean) | object,
reason: Error,
): Bluebird<R>;
catchThrow<E1 extends Error>(
filter1: (new (...args: any[]) => E1) | ((error: any) => boolean) | object,
catchThrow(
filter1: (new (...args: any[]) => Error) | ((error: any) => boolean) | object,
reason: Error,
): Bluebird<R>;
@@ -710,8 +721,7 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
/**
* Create a promise that is rejected with the given `reason`.
*/
static reject(reason: any): Bluebird<any>;
static reject<R>(reason: any): Bluebird<R>;
static reject(reason: any): Bluebird<never>;
/**
* Create a promise with undecided fate and return a `PromiseResolver` to control it. See resolution?: Promise(#promise-resolution).
@@ -767,7 +777,7 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
* Note that the original methods on the object are not overwritten but new methods are created with the `Async`-postfix. For example, if you `promisifyAll()` the node.js `fs` object use `fs.statAsync()` to call the promisified `stat` method.
*/
// TODO how to model promisifyAll?
static promisifyAll(target: object, options?: Bluebird.PromisifyAllOptions): object;
static promisifyAll<T extends object>(target: T, options?: Bluebird.PromisifyAllOptions<T>): T;
/**
* Returns a promise that is resolved by a node style callback function.
@@ -791,6 +801,7 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
static coroutine<T, A1, A2, A3, A4, A5, A6>(generatorFunction: (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6) => IterableIterator<any>, options?: Bluebird.CoroutineOptions): (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6) => Bluebird<T>;
static coroutine<T, A1, A2, A3, A4, A5, A6, A7>(generatorFunction: (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7) => IterableIterator<any>, options?: Bluebird.CoroutineOptions): (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7) => Bluebird<T>;
static coroutine<T, A1, A2, A3, A4, A5, A6, A7, A8>(generatorFunction: (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7, a8: A8) => IterableIterator<any>, options?: Bluebird.CoroutineOptions): (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7, a8: A8) => Bluebird<T>;
/**
* Add `handler` as the handler to call when there is a possibly unhandled rejection. The default handler logs the error stack to stderr or `console.error` in browsers.
*
@@ -798,6 +809,16 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
*/
static onPossiblyUnhandledRejection(handler: (reason: any) => any): void;
/**
* Add handler as the handler to call when there is a possibly unhandled rejection.
* The default handler logs the error stack to stderr or console.error in browsers.
*
* Passing no value or a non-function will have the effect of removing any kind of handling for possibly unhandled rejections.
*
* Note: this hook is specific to the bluebird instance its called on, application developers should use global rejection events.
*/
static onPossiblyUnhandledRejection(handler?: (error: Error, promise: Bluebird<any>) => void): void;
/**
* Given an array, or a promise of an array, which contains promises (or a mix of promises and values) return a promise that is fulfilled when all the items in the array are fulfilled. The promise's fulfillment value is an array with fulfillment values at respective positions to the original array. If any promise in the array rejects, the returned promise is rejected with the rejection reason.
*/
@@ -809,7 +830,7 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
static all<T1, T2>(values: [PromiseLike<T1> | T1, PromiseLike<T2> | T2]): Bluebird<[T1, T2]>;
static all<T1>(values: [PromiseLike<T1> | T1]): Bluebird<[T1]>;
// array with values
static all<R>(values: PromiseLike<Array<PromiseLike<R> | R>> | Array<PromiseLike<R> | R>): Bluebird<R[]>;
static all<R>(values: PromiseLike<Iterable<PromiseLike<R> | R>> | Iterable<PromiseLike<R> | R>): Bluebird<R[]>;
/**
* Like ``Promise.all`` but for object properties instead of array items. Returns a promise that is fulfilled when all the properties of the object are fulfilled. The promise's fulfillment value is an object with fulfillment values at respective keys to the original object. If any promise in the object rejects, the returned promise is rejected with the rejection reason.
@@ -818,26 +839,24 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
*
* *The original object is not modified.*
*/
// trusted promise for map
static props<K, V>(map: PromiseLike<Map<K, PromiseLike<V> | V>>): Bluebird<Map<K, V>>;
// map
static props<K, V>(map: PromiseLike<Map<K, PromiseLike<V> | V>> | Map<K, PromiseLike<V> | V>): Bluebird<Map<K, V>>;
// trusted promise for object
static props<T>(object: PromiseLike<Bluebird.ResolvableProps<T>>): Bluebird<T>; // tslint:disable-line:unified-signatures
// map
static props<K, V>(map: Map<K, PromiseLike<V> | V>): Bluebird<Map<K, V>>; // tslint:disable-line:unified-signatures
// object
static props<T>(object: Bluebird.ResolvableProps<T>): Bluebird<T>; // tslint:disable-line:unified-signatures
/**
* Like `Promise.some()`, with 1 as `count`. However, if the promise fulfills, the fulfillment value is not an array of 1 but the value directly.
*/
static any<R>(values: PromiseLike<Array<PromiseLike<R> | R>> | Array<PromiseLike<R> | R>): Bluebird<R>;
static any<R>(values: PromiseLike<Iterable<PromiseLike<R> | R>> | Iterable<PromiseLike<R> | R>): Bluebird<R>;
/**
* Given an array, or a promise of an array, which contains promises (or a mix of promises and values) return a promise that is fulfilled or rejected as soon as a promise in the array is fulfilled or rejected with the respective rejection reason or fulfillment value.
*
* **Note** If you pass empty array or a sparse array with no values, or a promise/thenable for such, it will be forever pending.
*/
static race<R>(values: PromiseLike<Array<PromiseLike<R> | R>> | Array<PromiseLike<R> | R>): Bluebird<R>;
static race<R>(values: PromiseLike<Iterable<PromiseLike<R> | R>> | Iterable<PromiseLike<R> | R>): Bluebird<R>;
/**
* Initiate a competetive race between multiple promises or values (values will become immediately fulfilled promises). When `count` amount of promises have been fulfilled, the returned promise is fulfilled with an array that contains the fulfillment values of the winners in order of resolution.
@@ -846,7 +865,7 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
*
* *The original array is not modified.*
*/
static some<R>(values: PromiseLike<Array<PromiseLike<R> | R>> | Array<PromiseLike<R> | R>, count: number): Bluebird<R[]>;
static some<R>(values: PromiseLike<Iterable<PromiseLike<R> | R>> | Iterable<PromiseLike<R> | R>, count: number): Bluebird<R[]>;
/**
* Promise.join(
@@ -874,7 +893,7 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
*
* *The original array is not modified.*
*/
static map<R, U>(values: PromiseLike<Array<PromiseLike<R> | R>> | Array<PromiseLike<R> | R>, mapper: (item: R, index: number, arrayLength: number) => U | PromiseLike<U>, options?: Bluebird.ConcurrencyOption): Bluebird<U[]>;
static map<R, U>(values: PromiseLike<Iterable<PromiseLike<R> | R>> | Iterable<PromiseLike<R> | R>, mapper: (item: R, index: number, arrayLength: number) => U | PromiseLike<U>, options?: Bluebird.ConcurrencyOption): Bluebird<U[]>;
/**
* Reduce an array, or a promise of an array, which contains a promises (or a mix of promises and values) with the given `reducer` function with the signature `(total, current, index, arrayLength)` where `item` is the resolved value of a respective promise in the input array. If any promise in the input array is rejected the returned promise is rejected as well.
@@ -883,7 +902,7 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
*
* *The original array is not modified. If no `intialValue` is given and the array doesn't contain at least 2 items, the callback will not be called and `undefined` is returned. If `initialValue` is given and the array doesn't have at least 1 item, `initialValue` is returned.*
*/
static reduce<R, U>(values: PromiseLike<Array<PromiseLike<R> | R>> | Array<PromiseLike<R> | R>, reducer: (total: U, current: R, index: number, arrayLength: number) => U | PromiseLike<U>, initialValue?: U): Bluebird<U>;
static reduce<R, U>(values: PromiseLike<Iterable<PromiseLike<R> | R>> | Iterable<PromiseLike<R> | R>, reducer: (total: U, current: R, index: number, arrayLength: number) => U | PromiseLike<U>, initialValue?: U): Bluebird<U>;
/**
* Filter an array, or a promise of an array, which contains a promises (or a mix of promises and values) with the given `filterer` function with the signature `(item, index, arrayLength)` where `item` is the resolved value of a respective promise in the input array. If any promise in the input array is rejected the returned promise is rejected as well.
@@ -892,14 +911,14 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
*
* *The original array is not modified.
*/
static filter<R>(values: PromiseLike<Array<PromiseLike<R> | R>> | Array<PromiseLike<R> | R>, filterer: (item: R, index: number, arrayLength: number) => boolean | PromiseLike<boolean>, option?: Bluebird.ConcurrencyOption): Bluebird<R[]>;
static filter<R>(values: PromiseLike<Iterable<PromiseLike<R> | R>> | Iterable<PromiseLike<R> | R>, filterer: (item: R, index: number, arrayLength: number) => boolean | PromiseLike<boolean>, option?: Bluebird.ConcurrencyOption): Bluebird<R[]>;
/**
* Iterate over an array, or a promise of an array, which contains promises (or a mix of promises and values) with the given iterator function with the signature (item, index, value) where item is the resolved value of a respective promise in the input array. Iteration happens serially. If any promise in the input array is rejected the returned promise is rejected as well.
*
* Resolves to the original array unmodified, this method is meant to be used for side effects. If the iterator function returns a promise or a thenable, the result for the promise is awaited for before continuing with next iteration.
*/
static each<R, U>(values: PromiseLike<Array<PromiseLike<R> | R>> | Array<PromiseLike<R> | R>, iterator: (item: R, index: number, arrayLength: number) => U | PromiseLike<U>): Bluebird<R[]>;
static each<R, U>(values: PromiseLike<Iterable<PromiseLike<R> | R>> | Iterable<PromiseLike<R> | R>, iterator: (item: R, index: number, arrayLength: number) => U | PromiseLike<U>): Bluebird<R[]>;
/**
* Given an Iterable(arrays are Iterable), or a promise of an Iterable, which produces promises (or a mix of promises and values), iterate over all the values in the Iterable into an array and iterate over the array serially, in-order.
@@ -908,7 +927,7 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
*
* If any promise in the input array is rejected or any promise returned by the iterator function is rejected, the result will be rejected as well.
*/
static mapSeries<R, U>(values: PromiseLike<Array<PromiseLike<R> | R>> | Array<PromiseLike<R> | R>, iterator: (item: R, index: number, arrayLength: number) => U | PromiseLike<U>): Bluebird<U[]>;
static mapSeries<R, U>(values: PromiseLike<Iterable<PromiseLike<R> | R>> | Iterable<PromiseLike<R> | R>, iterator: (item: R, index: number, arrayLength: number) => U | PromiseLike<U>): Bluebird<U[]>;
/**
* A meta method used to specify the disposer method that cleans up a resource when using `Promise.using`.
@@ -931,16 +950,6 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
static using<R1, R2, T>(disposer: Bluebird.Disposer<R1>, disposer2: Bluebird.Disposer<R2>, executor: (transaction1: R1, transaction2: R2) => PromiseLike<T>): Bluebird<T>;
static using<R1, R2, R3, T>(disposer: Bluebird.Disposer<R1>, disposer2: Bluebird.Disposer<R2>, disposer3: Bluebird.Disposer<R3>, executor: (transaction1: R1, transaction2: R2, transaction3: R3) => PromiseLike<T>): Bluebird<T>;
/**
* Add handler as the handler to call when there is a possibly unhandled rejection.
* The default handler logs the error stack to stderr or console.error in browsers.
*
* Passing no value or a non-function will have the effect of removing any kind of handling for possibly unhandled rejections.
*
* Note: this hook is specific to the bluebird instance its called on, application developers should use global rejection events.
*/
static onPossiblyUnhandledRejection(handler?: (error: Error, promise: Bluebird<any>) => void): void;
/**
* Configure long stack traces, warnings, monitoring and cancellation.
* Note that even though false is the default here, a development environment might be detected which automatically
@@ -986,11 +995,11 @@ declare namespace Bluebird {
context?: any;
multiArgs?: boolean;
}
interface PromisifyAllOptions extends PromisifyOptions {
interface PromisifyAllOptions<T> extends PromisifyOptions {
suffix?: string;
filter?(name: string, func: (...args: any[]) => any, target?: any, passesDefaultFilter?: boolean): boolean;
// The promisifier gets a reference to the original method and should return a function which returns a promise
promisifier?(originalMethod: (...args: any[]) => any, defaultPromisifer: (...args: any[]) => (...args: any[]) => Bluebird<any>): () => PromiseLike<any>;
promisifier?(this: T, originalMethod: (...args: any[]) => any, defaultPromisifer: (...args: any[]) => (...args: any[]) => Bluebird<any>): () => PromiseLike<any>;
}
interface CoroutineOptions {
yieldHandler(value: any): any;
@@ -1014,7 +1023,7 @@ declare namespace Bluebird {
/**
* Signals that an operation has been aborted or cancelled. The default reason used by `.cancel`.
*/
class CancellationError extends Error {}
class CancellationError extends Error { }
/**
* A collection of errors. `AggregateError` is an array-like object, with numeric indices and a `.length` property.
@@ -1049,12 +1058,12 @@ declare namespace Bluebird {
/**
* returned by `Bluebird.disposer()`.
*/
class Disposer<R> {}
class Disposer<R> { }
/** @deprecated Use PromiseLike<T> directly. */
type Thenable<T> = PromiseLike<T>;
type ResolvableProps<T> = object & { [K in keyof T]: PromiseLike<T[K]> | T[K] };
type ResolvableProps<T> = object & {[K in keyof T]: PromiseLike<T[K]> | T[K]};
interface Resolver<R> {
/**

View File

@@ -9,9 +9,9 @@
"es6"
],
"noImplicitAny": true,
"noImplicitThis": false,
"noImplicitThis": true,
"strictNullChecks": false,
"strictFunctionTypes": false,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
@@ -20,4 +20,4 @@
"noEmit": true,
"forceConsistentCasingInFileNames": true
}
}
}

View File

@@ -1,13 +1,9 @@
{
"extends": "dtslint/dt.json",
"rules": {
"adjacent-overload-signatures": false,
"max-line-length": [true, 490],
"no-redundant-undefined": false,
"no-unnecessary-callback-wrapper": false,
"no-unnecessary-generics": false,
"no-void-expression": false,
"prefer-const": false,
"void-return": false
"prefer-const": false
}
}

View File

@@ -8,7 +8,9 @@ move('/path/to/thing', '/new/path/thing').then(() => {
import * as Bluebird from 'bluebird';
const promise = move('/path/to/thing', '/new/path/thing', { Promise: Bluebird })
// tsc version: 2.7.0-dev.20171024
// required type arguments!
const promise = move<Bluebird<void>>('/path/to/thing', '/new/path/thing', { Promise: Bluebird })
.then(() => {
// thing is now moved!
})