mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-11 03:27:47 +08:00
Refactoring [@types/bluebird] (#27410)
* Define type Resolvable * use type Extract * fix ignore lint: max-line-length * fix ignore lint error: no-unnecessary-generics * enable strictNullChecks * Apply review * fix review * fix review
This commit is contained in:
@@ -7,13 +7,13 @@
|
||||
|
||||
import Promise = require("bluebird");
|
||||
|
||||
let obj: object;
|
||||
let bool: boolean;
|
||||
let num: number;
|
||||
let str: string;
|
||||
let err: Error;
|
||||
let x: any;
|
||||
let f: (...args: any[]) => any;
|
||||
let obj: object = {};
|
||||
let bool = false;
|
||||
let num = 0;
|
||||
let str = '';
|
||||
let err: Error = new Error();
|
||||
let x: any = 0;
|
||||
let f: (...args: any[]) => any = () => {};
|
||||
let asyncfunc: (...args: any[]) => Promise<any>;
|
||||
let arr: any[];
|
||||
let exp: RegExp;
|
||||
@@ -25,7 +25,6 @@ let numArr: number[];
|
||||
|
||||
let value: any;
|
||||
let reason: any;
|
||||
let insanity: any;
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
@@ -36,7 +35,10 @@ interface Bar {
|
||||
bar(): string;
|
||||
}
|
||||
interface Baz {
|
||||
baz(): string;
|
||||
baz(): string;
|
||||
}
|
||||
interface Qux {
|
||||
qux: string;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - -
|
||||
@@ -61,11 +63,12 @@ interface StrBarArrMap {
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
let foo: Foo;
|
||||
let bar: Bar;
|
||||
let baz: Baz;
|
||||
let foo: Foo = { foo() { return 'foo'; } };
|
||||
let bar: Bar = { bar() { return 'bar'; } };
|
||||
let baz: Baz = { baz() { return 'baz'; } };
|
||||
let qux: Qux = { qux: 'quix' };
|
||||
|
||||
let fooArr: Foo[];
|
||||
let fooArr: Foo[] = [foo];
|
||||
let barArr: Bar[];
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
@@ -74,13 +77,14 @@ let numProm: Promise<number>;
|
||||
let strProm: Promise<string>;
|
||||
let anyProm: Promise<any>;
|
||||
let boolProm: Promise<boolean>;
|
||||
let objProm: Promise<object>;
|
||||
let objProm: Promise<object> = Promise.resolve(obj);
|
||||
let voidProm: Promise<void>;
|
||||
|
||||
let fooProm: Promise<Foo>;
|
||||
let barProm: Promise<Bar>;
|
||||
let fooProm: Promise<Foo> = Promise.resolve(foo);
|
||||
let barProm: Promise<Bar> = Promise.resolve(bar);
|
||||
let fooOrBarProm: Promise<Foo | Bar>;
|
||||
let bazProm: Promise<Baz>;
|
||||
let bazProm: Promise<Baz> = Promise.resolve(baz);
|
||||
let quxProm: Promise<Qux> = Promise.resolve(qux);
|
||||
|
||||
// - - - - - - - - - - - - - - - - -
|
||||
|
||||
@@ -91,8 +95,8 @@ let boolThen: PromiseLike<boolean>;
|
||||
let objThen: PromiseLike<object>;
|
||||
let voidThen: PromiseLike<void>;
|
||||
|
||||
let fooThen: PromiseLike<Foo>;
|
||||
let barThen: PromiseLike<Bar>;
|
||||
let fooThen: PromiseLike<Foo> = fooProm;
|
||||
let barThen: PromiseLike<Bar> = barProm;
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
@@ -100,7 +104,7 @@ let numArrProm: Promise<number[]>;
|
||||
let strArrProm: Promise<string[]>;
|
||||
let anyArrProm: Promise<any[]>;
|
||||
|
||||
let fooArrProm: Promise<Foo[]>;
|
||||
let fooArrProm: Promise<Foo[]> = Promise.resolve(fooArr);
|
||||
let barArrProm: Promise<Bar[]>;
|
||||
|
||||
// - - - - - - - - - - - - - - - - -
|
||||
@@ -109,7 +113,7 @@ let numArrThen: PromiseLike<number[]>;
|
||||
let strArrThen: PromiseLike<string[]>;
|
||||
let anyArrThen: PromiseLike<any[]>;
|
||||
|
||||
let fooArrThen: PromiseLike<Foo[]>;
|
||||
let fooArrThen: PromiseLike<Foo[]> = fooArrProm;
|
||||
let barArrThen: PromiseLike<Bar[]>;
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
@@ -127,23 +131,19 @@ let numThenArr: Array<PromiseLike<number>>;
|
||||
let strThenArr: Array<PromiseLike<string>>;
|
||||
let anyThenArr: Array<PromiseLike<any>>;
|
||||
|
||||
let fooThenArr: Array<PromiseLike<Foo>>;
|
||||
let fooThenArr: Array<PromiseLike<Foo>> = [fooThen];
|
||||
let barThenArr: Array<PromiseLike<Bar>>;
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
// booya!
|
||||
let fooThenArrThen: PromiseLike<Array<PromiseLike<Foo>>>;
|
||||
let barThenArrThen: PromiseLike<Array<PromiseLike<Bar>>>;
|
||||
let fooThenArrThen: PromiseLike<Array<PromiseLike<Foo>>> = Promise.resolve(fooThenArr);
|
||||
|
||||
let fooResolver: Promise.Resolver<Foo>;
|
||||
let barResolver: Promise.Resolver<Bar>;
|
||||
|
||||
let fooInspection: Promise.Inspection<Foo>;
|
||||
let fooInspectionPromise: Promise<Promise.Inspection<Foo>>;
|
||||
|
||||
let fooInspectionArrProm: Promise<Array<Promise.Inspection<Foo>>>;
|
||||
let barInspectionArrProm: Promise<Array<Promise.Inspection<Bar>>>;
|
||||
|
||||
let BlueBird: typeof Promise;
|
||||
|
||||
@@ -192,19 +192,16 @@ fooProm = new Promise<Foo>((resolve) => {
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
fooResolver.resolve(foo);
|
||||
fooInspectionPromise = fooProm.reflect();
|
||||
|
||||
fooResolver.reject(err);
|
||||
|
||||
fooResolver.callback = (err: any, value: Foo) => {};
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
bool = fooInspection.isFulfilled();
|
||||
bool = fooInspection.isRejected();
|
||||
bool = fooInspection.isPending();
|
||||
foo = fooInspection.value();
|
||||
x = fooInspection.reason();
|
||||
fooInspectionPromise.then(value => {
|
||||
fooInspection = value;
|
||||
bool = fooInspection.isFulfilled();
|
||||
bool = fooInspection.isRejected();
|
||||
bool = fooInspection.isPending();
|
||||
foo = fooInspection.value();
|
||||
x = fooInspection.reason();
|
||||
});
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
@@ -235,8 +232,7 @@ barProm = fooProm.then((value: Foo) => {
|
||||
});
|
||||
barProm = barProm.then((value: Bar) => {
|
||||
if (value) return value;
|
||||
let b: Bar;
|
||||
return Promise.resolve(b);
|
||||
return Promise.resolve(bar);
|
||||
});
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
@@ -554,10 +550,13 @@ bool = fooProm.isResolved();
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
anyProm = fooProm.call("foo");
|
||||
anyProm = fooProm.call("foo", 1, 2, 3);
|
||||
strProm = fooProm.call("foo");
|
||||
strProm = fooProm.call("foo", 1, 2, 3);
|
||||
|
||||
voidProm = fooProm.get("foo").then((method) => { str = method(); });
|
||||
// $ExpectType Bluebird<never>
|
||||
quxProm.call("qux");
|
||||
|
||||
strProm = fooProm.get("foo").then(method => method());
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
@@ -607,8 +606,6 @@ fooArrProm = fooArrProm.all();
|
||||
// $ExpectType Bluebird<never>
|
||||
fooProm.all();
|
||||
|
||||
fooInspectionPromise = fooProm.reflect();
|
||||
|
||||
fooProm = fooArrProm.any();
|
||||
|
||||
// $ExpectType Bluebird<never>
|
||||
@@ -640,25 +637,25 @@ Promise.props(new Map<number, PromiseLike<string>>()).then(val => { propsMapValu
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
Promise.all([fooProm, barProm]).then(result => {
|
||||
result[0].foo();
|
||||
result[1].bar();
|
||||
foo = result[0];
|
||||
bar = result[1];
|
||||
});
|
||||
|
||||
Promise.all([fooProm, fooProm]).then(result => {
|
||||
result[0].foo();
|
||||
result[1].foo();
|
||||
foo = result[0];
|
||||
foo = result[1];
|
||||
});
|
||||
|
||||
Promise.all([fooProm, barProm, bazProm]).then(result => {
|
||||
result[0].foo();
|
||||
result[1].bar();
|
||||
result[2].baz();
|
||||
foo = result[0];
|
||||
bar = result[1];
|
||||
baz = result[2];
|
||||
});
|
||||
|
||||
Promise.all([fooProm, barProm, fooProm]).then(result => {
|
||||
result[0].foo();
|
||||
result[1].bar();
|
||||
result[2].foo();
|
||||
foo = result[0];
|
||||
bar = result[1];
|
||||
foo = result[2];
|
||||
});
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
@@ -722,7 +719,7 @@ fooArrProm = fooArrProm.filter((item: Foo) => {
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
fooArrProm = fooArrProm.each((item: Foo): Bar => bar);
|
||||
fooArrProm = fooArrProm.each((item: Foo, index: number): Bar => index ? bar : null);
|
||||
fooArrProm = fooArrProm.each((item: Foo, index: number) => index ? bar : null);
|
||||
fooArrProm = fooArrProm.each((item: Foo, index: number, arrayLength: number): Bar => bar);
|
||||
fooArrProm = fooArrProm.each((item: Foo, index: number, arrayLength: number): Promise<Bar> => barProm);
|
||||
|
||||
@@ -815,6 +812,12 @@ voidProm = Promise.reject(reason);
|
||||
|
||||
fooResolver = Promise.defer<Foo>();
|
||||
|
||||
fooResolver.resolve(foo);
|
||||
|
||||
fooResolver.reject(err);
|
||||
|
||||
fooResolver.callback = (err: any, value: Foo) => {};
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
fooProm = Promise.cast(foo);
|
||||
@@ -879,11 +882,18 @@ obj = Promise.promisifyAll(obj, {
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
const generator = function*(a: number, b: string) { return "string"; };
|
||||
const coroutine = Promise.coroutine<string, number, string>(generator);
|
||||
coroutine(5, "foo").then((x: string) => {});
|
||||
const generator1 = function*(a: number, b: string) { return "string"; };
|
||||
const coroutine1 = Promise.coroutine<string, number, string>(generator1);
|
||||
strProm = coroutine1(5, "foo");
|
||||
|
||||
const coroutineCustomYield = Promise.coroutine(generator, { yieldHandler: (value) => "whatever" });
|
||||
const generator2 = function*(a: number, b: string) {
|
||||
yield foo;
|
||||
return bar;
|
||||
};
|
||||
const coroutine2 = Promise.coroutine<Bar, number, string>(generator2);
|
||||
barProm = coroutine2(5, "foo");
|
||||
|
||||
const coroutineCustomYield = Promise.coroutine(generator1, { yieldHandler: (value) => "whatever" });
|
||||
/*
|
||||
barProm = Promise.spawn<number>(f);
|
||||
*/
|
||||
|
||||
254
types/bluebird/index.d.ts
vendored
254
types/bluebird/index.d.ts
vendored
@@ -37,14 +37,19 @@
|
||||
|
||||
type CatchFilter<E> = (new (...args: any[]) => E) | ((error: E) => boolean) | (object & E);
|
||||
type IterableItem<R> = R extends Iterable<infer U> ? U : never;
|
||||
type IterableOrNever<R> = R extends Iterable<any> ? R : never;
|
||||
type IterableOrNever<R> = Extract<R, Iterable<any>>;
|
||||
type Resolvable<R> = R | PromiseLike<R>;
|
||||
type IterateFunction<T, R> = (item: T, index: number, arrayLength: number) => Resolvable<R>;
|
||||
|
||||
declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
|
||||
/**
|
||||
* Create a new promise. The passed in function will receive functions `resolve` and `reject` as its arguments which can be called to seal the fate of the created promise.
|
||||
* If promise cancellation is enabled, passed in function will receive one more function argument `onCancel` that allows to register an optional cancellation callback.
|
||||
* Create a new promise. The passed in function will receive functions
|
||||
* `resolve` and `reject` as its arguments which can be called to seal the fate of the created promise.
|
||||
*
|
||||
* If promise cancellation is enabled, passed in function will receive
|
||||
* one more function argument `onCancel` that allows to register an optional cancellation callback.
|
||||
*/
|
||||
constructor(callback: (resolve: (thenableOrResult?: R | PromiseLike<R>) => void, reject: (error?: any) => void, onCancel?: (callback: () => void) => void) => void);
|
||||
constructor(callback: (resolve: (thenableOrResult?: Resolvable<R>) => void, reject: (error?: any) => void, onCancel?: (callback: () => void) => void) => void);
|
||||
|
||||
/**
|
||||
* Promises/A+ `.then()`. Returns a new promise chained from this promise.
|
||||
@@ -52,10 +57,10 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
|
||||
* The new promise will be rejected or resolved depending on the passed `fulfilledHandler`, `rejectedHandler` and the state of this promise.
|
||||
*/
|
||||
// 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<U>(onFulfill?: (value: R) => Resolvable<U>, onReject?: (error: any) => Resolvable<U>): Bluebird<U>; // For simpler signature help.
|
||||
then<TResult1 = R, TResult2 = never>(
|
||||
onfulfilled?: ((value: R) => TResult1 | PromiseLike<TResult1>) | null,
|
||||
onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null
|
||||
onfulfilled?: ((value: R) => Resolvable<TResult1>) | null,
|
||||
onrejected?: ((reason: any) => Resolvable<TResult2>) | null
|
||||
): Bluebird<TResult1 | TResult2>;
|
||||
|
||||
/**
|
||||
@@ -65,8 +70,8 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
|
||||
*
|
||||
* Alias `.caught();` for compatibility with earlier ECMAScript version.
|
||||
*/
|
||||
catch(onReject: (error: any) => R | PromiseLike<R>): Bluebird<R>;
|
||||
catch<U>(onReject: ((error: any) => U | PromiseLike<U>) | undefined | null): Bluebird<U | R>;
|
||||
catch(onReject: (error: any) => Resolvable<R>): Bluebird<R>;
|
||||
catch<U>(onReject: ((error: any) => Resolvable<U>) | undefined | null): Bluebird<U | R>;
|
||||
|
||||
/**
|
||||
* This extends `.catch` to work more like catch-clauses in languages like Java or C#.
|
||||
@@ -87,7 +92,7 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
|
||||
filter3: CatchFilter<E3>,
|
||||
filter4: CatchFilter<E4>,
|
||||
filter5: CatchFilter<E5>,
|
||||
onReject: (error: E1 | E2 | E3 | E4 | E5) => R | PromiseLike<R>,
|
||||
onReject: (error: E1 | E2 | E3 | E4 | E5) => Resolvable<R>,
|
||||
): Bluebird<R>;
|
||||
catch<U, E1, E2, E3, E4, E5>(
|
||||
filter1: CatchFilter<E1>,
|
||||
@@ -95,7 +100,7 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
|
||||
filter3: CatchFilter<E3>,
|
||||
filter4: CatchFilter<E4>,
|
||||
filter5: CatchFilter<E5>,
|
||||
onReject: (error: E1 | E2 | E3 | E4 | E5) => U | PromiseLike<U>,
|
||||
onReject: (error: E1 | E2 | E3 | E4 | E5) => Resolvable<U>,
|
||||
): Bluebird<U | R>;
|
||||
|
||||
catch<E1, E2, E3, E4>(
|
||||
@@ -103,7 +108,7 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
|
||||
filter2: CatchFilter<E2>,
|
||||
filter3: CatchFilter<E3>,
|
||||
filter4: CatchFilter<E4>,
|
||||
onReject: (error: E1 | E2 | E3 | E4) => R | PromiseLike<R>,
|
||||
onReject: (error: E1 | E2 | E3 | E4) => Resolvable<R>,
|
||||
): Bluebird<R>;
|
||||
|
||||
catch<U, E1, E2, E3, E4>(
|
||||
@@ -111,40 +116,40 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
|
||||
filter2: CatchFilter<E2>,
|
||||
filter3: CatchFilter<E3>,
|
||||
filter4: CatchFilter<E4>,
|
||||
onReject: (error: E1 | E2 | E3 | E4) => U | PromiseLike<U>,
|
||||
onReject: (error: E1 | E2 | E3 | E4) => Resolvable<U>,
|
||||
): Bluebird<U | R>;
|
||||
|
||||
catch<E1, E2, E3>(
|
||||
filter1: CatchFilter<E1>,
|
||||
filter2: CatchFilter<E2>,
|
||||
filter3: CatchFilter<E3>,
|
||||
onReject: (error: E1 | E2 | E3) => R | PromiseLike<R>,
|
||||
onReject: (error: E1 | E2 | E3) => Resolvable<R>,
|
||||
): Bluebird<R>;
|
||||
catch<U, E1, E2, E3>(
|
||||
filter1: CatchFilter<E1>,
|
||||
filter2: CatchFilter<E2>,
|
||||
filter3: CatchFilter<E3>,
|
||||
onReject: (error: E1 | E2 | E3) => U | PromiseLike<U>,
|
||||
onReject: (error: E1 | E2 | E3) => Resolvable<U>,
|
||||
): Bluebird<U | R>;
|
||||
|
||||
catch<E1, E2>(
|
||||
filter1: CatchFilter<E1>,
|
||||
filter2: CatchFilter<E2>,
|
||||
onReject: (error: E1 | E2) => R | PromiseLike<R>,
|
||||
onReject: (error: E1 | E2) => Resolvable<R>,
|
||||
): Bluebird<R>;
|
||||
catch<U, E1, E2>(
|
||||
filter1: CatchFilter<E1>,
|
||||
filter2: CatchFilter<E2>,
|
||||
onReject: (error: E1 | E2) => U | PromiseLike<U>,
|
||||
onReject: (error: E1 | E2) => Resolvable<U>,
|
||||
): Bluebird<U | R>;
|
||||
|
||||
catch<E1>(
|
||||
filter1: CatchFilter<E1>,
|
||||
onReject: (error: E1) => R | PromiseLike<R>,
|
||||
onReject: (error: E1) => Resolvable<R>,
|
||||
): Bluebird<R>;
|
||||
catch<U, E1>(
|
||||
filter1: CatchFilter<E1>,
|
||||
onReject: (error: E1) => U | PromiseLike<U>,
|
||||
onReject: (error: E1) => Resolvable<U>,
|
||||
): Bluebird<U | R>;
|
||||
|
||||
/**
|
||||
@@ -157,9 +162,10 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
|
||||
caught: Bluebird<R>["catch"];
|
||||
|
||||
/**
|
||||
* Like `.catch` but instead of catching all types of exceptions, it only catches those that don't originate from thrown errors but rather from explicit rejections.
|
||||
* Like `.catch` but instead of catching all types of exceptions,
|
||||
* it only catches those that don't originate from thrown errors but rather from explicit rejections.
|
||||
*/
|
||||
error<U>(onReject: (reason: any) => U | PromiseLike<U>): Bluebird<U>;
|
||||
error<U>(onReject: (reason: any) => Resolvable<U>): Bluebird<U>;
|
||||
|
||||
/**
|
||||
* Pass a handler that will be called regardless of this promise's fate. Returns a new promise chained from this promise.
|
||||
@@ -168,12 +174,13 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
|
||||
*
|
||||
* Alias `.lastly();` for compatibility with earlier ECMAScript version.
|
||||
*/
|
||||
finally<U>(handler: () => U | PromiseLike<U>): Bluebird<R>;
|
||||
finally(handler: () => Resolvable<any>): Bluebird<R>;
|
||||
|
||||
lastly<U>(handler: () => U | PromiseLike<U>): Bluebird<R>;
|
||||
lastly: Bluebird<R>["finally"];
|
||||
|
||||
/**
|
||||
* Create a promise that follows this promise, but is bound to the given `thisArg` value. A bound promise will call its handlers with the bound value set to `this`.
|
||||
* Create a promise that follows this promise, but is bound to the given `thisArg` value.
|
||||
* A bound promise will call its handlers with the bound value set to `this`.
|
||||
*
|
||||
* Additionally promises derived from a bound promise will also be bound promises with the same `thisArg` binding as the original promise.
|
||||
*/
|
||||
@@ -182,47 +189,47 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
|
||||
/**
|
||||
* Like `.then()`, but any unhandled rejection that ends up here will be thrown as an error.
|
||||
*/
|
||||
done<U>(onFulfilled?: (value: R) => U | PromiseLike<U>, onRejected?: (error: any) => U | PromiseLike<U>): void;
|
||||
done<U>(onFulfilled?: (value: R) => Resolvable<U>, onRejected?: (error: any) => Resolvable<U>): void;
|
||||
|
||||
/**
|
||||
* Like `.finally()`, but not called for rejections.
|
||||
*/
|
||||
tap<U>(onFulFill: (value: R) => PromiseLike<U> | U): Bluebird<R>;
|
||||
tap(onFulFill: (value: R) => Resolvable<any>): Bluebird<R>;
|
||||
|
||||
/**
|
||||
* Like `.catch()` but rethrows the error
|
||||
*/
|
||||
tapCatch<U>(onReject: (error?: any) => U | PromiseLike<U>): Bluebird<R>;
|
||||
tapCatch(onReject: (error?: any) => Resolvable<any>): Bluebird<R>;
|
||||
|
||||
tapCatch<U, E1, E2, E3, E4, E5>(
|
||||
tapCatch<E1, E2, E3, E4, E5>(
|
||||
filter1: CatchFilter<E1>,
|
||||
filter2: CatchFilter<E2>,
|
||||
filter3: CatchFilter<E3>,
|
||||
filter4: CatchFilter<E4>,
|
||||
filter5: CatchFilter<E5>,
|
||||
onReject: (error: E1 | E2 | E3 | E4 | E5) => U | PromiseLike<U>,
|
||||
onReject: (error: E1 | E2 | E3 | E4 | E5) => Resolvable<any>,
|
||||
): Bluebird<R>;
|
||||
tapCatch<U, E1, E2, E3, E4>(
|
||||
tapCatch<E1, E2, E3, E4>(
|
||||
filter1: CatchFilter<E1>,
|
||||
filter2: CatchFilter<E2>,
|
||||
filter3: CatchFilter<E3>,
|
||||
filter4: CatchFilter<E4>,
|
||||
onReject: (error: E1 | E2 | E3 | E4) => U | PromiseLike<U>,
|
||||
onReject: (error: E1 | E2 | E3 | E4) => Resolvable<any>,
|
||||
): Bluebird<R>;
|
||||
tapCatch<U, E1, E2, E3>(
|
||||
tapCatch<E1, E2, E3>(
|
||||
filter1: CatchFilter<E1>,
|
||||
filter2: CatchFilter<E2>,
|
||||
filter3: CatchFilter<E3>,
|
||||
onReject: (error: E1 | E2 | E3) => U | PromiseLike<U>,
|
||||
onReject: (error: E1 | E2 | E3) => Resolvable<any>,
|
||||
): Bluebird<R>;
|
||||
tapCatch<U, E1, E2>(
|
||||
tapCatch<E1, E2>(
|
||||
filter1: CatchFilter<E1>,
|
||||
filter2: CatchFilter<E2>,
|
||||
onReject: (error: E1 | E2) => U | PromiseLike<U>,
|
||||
onReject: (error: E1 | E2) => Resolvable<any>,
|
||||
): Bluebird<R>;
|
||||
tapCatch<U, E1>(
|
||||
tapCatch<E1>(
|
||||
filter1: CatchFilter<E1>,
|
||||
onReject: (error: E1) => U | PromiseLike<U>,
|
||||
onReject: (error: E1) => Resolvable<any>,
|
||||
): Bluebird<R>;
|
||||
|
||||
/**
|
||||
@@ -243,7 +250,9 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
|
||||
* Register a node-style callback on this promise.
|
||||
*
|
||||
* When this promise is is either fulfilled or rejected,
|
||||
* the node callback will be called back with the node.js convention where error reason is the first argument and success value is the second argument.
|
||||
* the node callback will be called back with the node.js convention
|
||||
* where error reason is the first argument and success value is the second argument.
|
||||
*
|
||||
* The error argument will be `null` in case of success.
|
||||
* If the `callback` argument is not a function, this method does not do anything.
|
||||
*/
|
||||
@@ -307,7 +316,7 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
|
||||
* });
|
||||
* </code>
|
||||
*/
|
||||
call(propertyName: keyof R, ...args: any[]): Bluebird<any>;
|
||||
call<U extends keyof R>(propertyName: U, ...args: any[]): Bluebird<R[U] extends (...args: any[]) => any ? ReturnType<R[U]> : never>;
|
||||
|
||||
/**
|
||||
* This is a convenience method for doing:
|
||||
@@ -455,7 +464,7 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
|
||||
/**
|
||||
* Like calling `.then`, but the fulfillment value or rejection reason is assumed to be an array, which is flattened to the formal parameters of the handlers.
|
||||
*/
|
||||
spread<U>(fulfilledHandler: (...values: Array<IterableItem<R>>) => U | PromiseLike<U>): Bluebird<U>;
|
||||
spread<U>(fulfilledHandler: (...values: Array<IterableItem<R>>) => Resolvable<U>): Bluebird<U>;
|
||||
|
||||
/**
|
||||
* Same as calling `Promise.all(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
|
||||
@@ -465,7 +474,7 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
|
||||
/**
|
||||
* Same as calling `Promise.props(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
|
||||
*/
|
||||
props<K, V>(this: PromiseLike<Map<K, PromiseLike<V> | V>>): Bluebird<Map<K, V>>;
|
||||
props<K, V>(this: PromiseLike<Map<K, Resolvable<V>>>): Bluebird<Map<K, V>>;
|
||||
props<T>(this: PromiseLike<Bluebird.ResolvableProps<T>>): Bluebird<T>;
|
||||
|
||||
/**
|
||||
@@ -486,27 +495,27 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
|
||||
/**
|
||||
* Same as calling `Bluebird.map(thisPromise, mapper)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
|
||||
*/
|
||||
map<U>(mapper: (item: IterableItem<R>, index: number, arrayLength: number) => U | PromiseLike<U>, options?: Bluebird.ConcurrencyOption): Bluebird<R extends Iterable<any> ? U[] : never>;
|
||||
map<U>(mapper: IterateFunction<IterableItem<R>, U>, options?: Bluebird.ConcurrencyOption): Bluebird<R extends Iterable<any> ? U[] : never>;
|
||||
|
||||
/**
|
||||
* Same as calling `Promise.reduce(thisPromise, Function reducer, initialValue)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
|
||||
*/
|
||||
reduce<U>(reducer: (memo: U, item: IterableItem<R>, index: number, arrayLength: number) => U | PromiseLike<U>, initialValue?: U): Bluebird<R extends Iterable<any> ? U : never>;
|
||||
reduce<U>(reducer: (memo: U, item: IterableItem<R>, index: number, arrayLength: number) => Resolvable<U>, initialValue?: U): Bluebird<R extends Iterable<any> ? U : never>;
|
||||
|
||||
/**
|
||||
* Same as calling ``Promise.filter(thisPromise, filterer)``. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
|
||||
*/
|
||||
filter(filterer: (item: IterableItem<R>, index: number, arrayLength: number) => boolean | PromiseLike<boolean>, options?: Bluebird.ConcurrencyOption): Bluebird<IterableOrNever<R>>;
|
||||
filter(filterer: IterateFunction<IterableItem<R>, boolean>, options?: Bluebird.ConcurrencyOption): Bluebird<IterableOrNever<R>>;
|
||||
|
||||
/**
|
||||
* Same as calling ``Bluebird.each(thisPromise, iterator)``. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
|
||||
*/
|
||||
each<U>(iterator: (item: IterableItem<R>, index: number, arrayLength: number) => U | PromiseLike<U>): Bluebird<IterableOrNever<R>>;
|
||||
each(iterator: IterateFunction<IterableItem<R>, any>): Bluebird<IterableOrNever<R>>;
|
||||
|
||||
/**
|
||||
* Same as calling ``Bluebird.mapSeries(thisPromise, iterator)``. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
|
||||
*/
|
||||
mapSeries<U>(iterator: (item: IterableItem<R>, index: number, arrayLength: number) => U | PromiseLike<U>): Bluebird<R extends Iterable<any> ? U[] : never>;
|
||||
mapSeries<U>(iterator: IterateFunction<IterableItem<R>, U>): Bluebird<R extends Iterable<any> ? U[] : never>;
|
||||
|
||||
/**
|
||||
* Cancel this `promise`. Will not do anything if this promise is already settled or if the cancellation feature has not been enabled
|
||||
@@ -528,27 +537,27 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
|
||||
*
|
||||
* Alias for `attempt();` for compatibility with earlier ECMAScript version.
|
||||
*/
|
||||
static try<R>(fn: () => R | PromiseLike<R>): Bluebird<R>;
|
||||
static attempt<R>(fn: () => R | PromiseLike<R>): Bluebird<R>;
|
||||
static try<R>(fn: () => Resolvable<R>): Bluebird<R>;
|
||||
static attempt<R>(fn: () => Resolvable<R>): Bluebird<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.
|
||||
* This method is convenient when a function can sometimes return synchronously or throw synchronously.
|
||||
*/
|
||||
static method<R>(fn: () => R | PromiseLike<R>): () => Bluebird<R>;
|
||||
static method<R, A1>(fn: (arg1: A1) => R | PromiseLike<R>): (arg1: A1) => Bluebird<R>;
|
||||
static method<R, A1, A2>(fn: (arg1: A1, arg2: A2) => R | PromiseLike<R>): (arg1: A1, arg2: A2) => Bluebird<R>;
|
||||
static method<R, A1, A2, A3>(fn: (arg1: A1, arg2: A2, arg3: A3) => R | PromiseLike<R>): (arg1: A1, arg2: A2, arg3: A3) => Bluebird<R>;
|
||||
static method<R, A1, A2, A3, A4>(fn: (arg1: A1, arg2: A2, arg3: A3, arg4: A4) => R | PromiseLike<R>): (arg1: A1, arg2: A2, arg3: A3, arg4: A4) => Bluebird<R>;
|
||||
static method<R, A1, A2, A3, A4, A5>(fn: (arg1: A1, arg2: A2, arg3: A3, arg4: A4, arg5: A5) => R | PromiseLike<R>): (arg1: A1, arg2: A2, arg3: A3, arg4: A4, arg5: A5) => Bluebird<R>;
|
||||
static method<R>(fn: (...args: any[]) => R | PromiseLike<R>): (...args: any[]) => Bluebird<R>;
|
||||
static method<R>(fn: () => Resolvable<R>): () => Bluebird<R>;
|
||||
static method<R, A1>(fn: (arg1: A1) => Resolvable<R>): (arg1: A1) => Bluebird<R>;
|
||||
static method<R, A1, A2>(fn: (arg1: A1, arg2: A2) => Resolvable<R>): (arg1: A1, arg2: A2) => Bluebird<R>;
|
||||
static method<R, A1, A2, A3>(fn: (arg1: A1, arg2: A2, arg3: A3) => Resolvable<R>): (arg1: A1, arg2: A2, arg3: A3) => Bluebird<R>;
|
||||
static method<R, A1, A2, A3, A4>(fn: (arg1: A1, arg2: A2, arg3: A3, arg4: A4) => Resolvable<R>): (arg1: A1, arg2: A2, arg3: A3, arg4: A4) => Bluebird<R>;
|
||||
static method<R, A1, A2, A3, A4, A5>(fn: (arg1: A1, arg2: A2, arg3: A3, arg4: A4, arg5: A5) => Resolvable<R>): (arg1: A1, arg2: A2, arg3: A3, arg4: A4, arg5: A5) => Bluebird<R>;
|
||||
static method<R>(fn: (...args: any[]) => Resolvable<R>): (...args: any[]) => Bluebird<R>;
|
||||
|
||||
/**
|
||||
* Create a promise that is resolved with the given `value`. If `value` is a thenable or promise, the returned promise will assume its state.
|
||||
*/
|
||||
static resolve(): Bluebird<void>;
|
||||
static resolve<R>(value: R | PromiseLike<R>): Bluebird<R>;
|
||||
static resolve<R>(value: Resolvable<R>): Bluebird<R>;
|
||||
|
||||
/**
|
||||
* Create a promise that is rejected with the given `reason`.
|
||||
@@ -556,9 +565,11 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
|
||||
static reject(reason: any): Bluebird<never>;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* Create a promise with undecided fate and return a `PromiseResolver` to control it. See resolution?: Promise(#promise-resolution).
|
||||
* @see http://bluebirdjs.com/docs/deprecated-apis.html#promise-resolution
|
||||
*/
|
||||
static defer<R>(): Bluebird.Resolver<R>;
|
||||
static defer<R>(): Bluebird.Resolver<R>; // tslint:disable-line no-unnecessary-generics
|
||||
|
||||
/**
|
||||
* Cast the given `value` to a trusted promise.
|
||||
@@ -566,7 +577,7 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
|
||||
* If `value` is already a trusted `Promise`, it is returned as is. If `value` is not a thenable, a fulfilled is: Promise returned with `value` as its fulfillment value.
|
||||
* If `value` is a thenable (Promise-like object, like those returned by jQuery's `$.ajax`), returns a trusted that: Promise assimilates the state of the thenable.
|
||||
*/
|
||||
static cast<R>(value: R | PromiseLike<R>): Bluebird<R>;
|
||||
static cast<R>(value: Resolvable<R>): Bluebird<R>;
|
||||
|
||||
/**
|
||||
* Sugar for `Promise.resolve(undefined).bind(thisArg);`. See `.bind()`.
|
||||
@@ -591,7 +602,7 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
|
||||
* If value is a promise, the delay will start counting down when it is fulfilled and the returned
|
||||
* promise will be fulfilled with the fulfillment value of the value promise.
|
||||
*/
|
||||
static delay<R>(ms: number, value: R | PromiseLike<R>): Bluebird<R>;
|
||||
static delay<R>(ms: number, value: Resolvable<R>): Bluebird<R>;
|
||||
static delay(ms: number): Bluebird<void>;
|
||||
|
||||
/**
|
||||
@@ -645,9 +656,7 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
|
||||
/**
|
||||
* Returns a promise that is resolved by a node style callback function.
|
||||
*/
|
||||
static fromNode(resolver: (callback: (err: any, result?: any) => void) => void, options?: Bluebird.FromNodeOptions): Bluebird<any>;
|
||||
static fromNode<T>(resolver: (callback: (err: any, result?: T) => void) => void, options?: Bluebird.FromNodeOptions): Bluebird<T>;
|
||||
static fromCallback(resolver: (callback: (err: any, result?: any) => void) => void, options?: Bluebird.FromNodeOptions): Bluebird<any>;
|
||||
static fromCallback<T>(resolver: (callback: (err: any, result?: T) => void) => void, options?: Bluebird.FromNodeOptions): Bluebird<T>;
|
||||
|
||||
/**
|
||||
@@ -719,13 +728,13 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
|
||||
*/
|
||||
// TODO enable more overloads
|
||||
// array with promises of different types
|
||||
static all<T1, T2, T3, T4, T5>(values: [PromiseLike<T1> | T1, PromiseLike<T2> | T2, PromiseLike<T3> | T3, PromiseLike<T4> | T4, PromiseLike<T5> | T5]): Bluebird<[T1, T2, T3, T4, T5]>;
|
||||
static all<T1, T2, T3, T4>(values: [PromiseLike<T1> | T1, PromiseLike<T2> | T2, PromiseLike<T3> | T3, PromiseLike<T4> | T4]): Bluebird<[T1, T2, T3, T4]>;
|
||||
static all<T1, T2, T3>(values: [PromiseLike<T1> | T1, PromiseLike<T2> | T2, PromiseLike<T3> | T3]): Bluebird<[T1, T2, T3]>;
|
||||
static all<T1, T2>(values: [PromiseLike<T1> | T1, PromiseLike<T2> | T2]): Bluebird<[T1, T2]>;
|
||||
static all<T1>(values: [PromiseLike<T1> | T1]): Bluebird<[T1]>;
|
||||
static all<T1, T2, T3, T4, T5>(values: [Resolvable<T1>, Resolvable<T2>, Resolvable<T3>, Resolvable<T4>, Resolvable<T5>]): Bluebird<[T1, T2, T3, T4, T5]>;
|
||||
static all<T1, T2, T3, T4>(values: [Resolvable<T1>, Resolvable<T2>, Resolvable<T3>, Resolvable<T4>]): Bluebird<[T1, T2, T3, T4]>;
|
||||
static all<T1, T2, T3>(values: [Resolvable<T1>, Resolvable<T2>, Resolvable<T3>]): Bluebird<[T1, T2, T3]>;
|
||||
static all<T1, T2>(values: [Resolvable<T1>, Resolvable<T2>]): Bluebird<[T1, T2]>;
|
||||
static all<T1>(values: [Resolvable<T1>]): Bluebird<[T1]>;
|
||||
// array with values
|
||||
static all<R>(values: PromiseLike<Iterable<PromiseLike<R> | R>> | Iterable<PromiseLike<R> | R>): Bluebird<R[]>;
|
||||
static all<R>(values: Resolvable<Iterable<Resolvable<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.
|
||||
@@ -739,7 +748,7 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
|
||||
* *The original object is not modified.*
|
||||
*/
|
||||
// map
|
||||
static props<K, V>(map: PromiseLike<Map<K, PromiseLike<V> | V>> | Map<K, PromiseLike<V> | V>): Bluebird<Map<K, V>>;
|
||||
static props<K, V>(map: Resolvable<Map<K, Resolvable<V>>>): Bluebird<Map<K, V>>;
|
||||
// trusted promise for object
|
||||
static props<T>(object: PromiseLike<Bluebird.ResolvableProps<T>>): Bluebird<T>; // tslint:disable-line:unified-signatures
|
||||
// object
|
||||
@@ -748,24 +757,27 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
|
||||
/**
|
||||
* 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<Iterable<PromiseLike<R> | R>> | Iterable<PromiseLike<R> | R>): Bluebird<R>;
|
||||
static any<R>(values: Resolvable<Iterable<Resolvable<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.
|
||||
* 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<Iterable<PromiseLike<R> | R>> | Iterable<PromiseLike<R> | R>): Bluebird<R>;
|
||||
static race<R>(values: Resolvable<Iterable<Resolvable<R>>>): Bluebird<R>;
|
||||
|
||||
/**
|
||||
* Initiate a competitive 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.
|
||||
* 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.
|
||||
*
|
||||
* If too many promises are rejected so that the promise can never become fulfilled, it will be immediately rejected with an array of rejection reasons in the order they were thrown in.
|
||||
* If too many promises are rejected so that the promise can never become fulfilled,
|
||||
* it will be immediately rejected with an array of rejection reasons in the order they were thrown in.
|
||||
*
|
||||
* *The original array is not modified.*
|
||||
*/
|
||||
static some<R>(values: PromiseLike<Iterable<PromiseLike<R> | R>> | Iterable<PromiseLike<R> | R>, count: number): Bluebird<R[]>;
|
||||
static some<R>(values: Resolvable<Iterable<Resolvable<R>>>, count: number): Bluebird<R[]>;
|
||||
|
||||
/**
|
||||
* Promise.join(
|
||||
@@ -778,42 +790,44 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
|
||||
* This behavior has been deprecated but is still supported partially - when the last argument is an immediate function value the new semantics will apply
|
||||
*/
|
||||
static join<R, A1>(
|
||||
arg1: A1 | PromiseLike<A1>,
|
||||
handler: (arg1: A1) => R | PromiseLike<R>
|
||||
arg1: Resolvable<A1>,
|
||||
handler: (arg1: A1) => Resolvable<R>
|
||||
): Bluebird<R>;
|
||||
static join<R, A1, A2>(
|
||||
arg1: A1 | PromiseLike<A1>,
|
||||
arg2: A2 | PromiseLike<A2>,
|
||||
handler: (arg1: A1, arg2: A2) => R | PromiseLike<R>
|
||||
arg1: Resolvable<A1>,
|
||||
arg2: Resolvable<A2>,
|
||||
handler: (arg1: A1, arg2: A2) => Resolvable<R>
|
||||
): Bluebird<R>;
|
||||
static join<R, A1, A2, A3>(
|
||||
arg1: A1 | PromiseLike<A1>,
|
||||
arg2: A2 | PromiseLike<A2>,
|
||||
arg3: A3 | PromiseLike<A3>,
|
||||
handler: (arg1: A1, arg2: A2, arg3: A3) => R | PromiseLike<R>
|
||||
arg1: Resolvable<A1>,
|
||||
arg2: Resolvable<A2>,
|
||||
arg3: Resolvable<A3>,
|
||||
handler: (arg1: A1, arg2: A2, arg3: A3) => Resolvable<R>
|
||||
): Bluebird<R>;
|
||||
static join<R, A1, A2, A3, A4>(
|
||||
arg1: A1 | PromiseLike<A1>,
|
||||
arg2: A2 | PromiseLike<A2>,
|
||||
arg3: A3 | PromiseLike<A3>,
|
||||
arg4: A4 | PromiseLike<A4>,
|
||||
handler: (arg1: A1, arg2: A2, arg3: A3, arg4: A4) => R | PromiseLike<R>
|
||||
arg1: Resolvable<A1>,
|
||||
arg2: Resolvable<A2>,
|
||||
arg3: Resolvable<A3>,
|
||||
arg4: Resolvable<A4>,
|
||||
handler: (arg1: A1, arg2: A2, arg3: A3, arg4: A4) => Resolvable<R>
|
||||
): Bluebird<R>;
|
||||
static join<R, A1, A2, A3, A4, A5>(
|
||||
arg1: A1 | PromiseLike<A1>,
|
||||
arg2: A2 | PromiseLike<A2>,
|
||||
arg3: A3 | PromiseLike<A3>,
|
||||
arg4: A4 | PromiseLike<A4>,
|
||||
arg5: A5 | PromiseLike<A5>,
|
||||
handler: (arg1: A1, arg2: A2, arg3: A3, arg4: A4, arg5: A5) => R | PromiseLike<R>
|
||||
arg1: Resolvable<A1>,
|
||||
arg2: Resolvable<A2>,
|
||||
arg3: Resolvable<A3>,
|
||||
arg4: Resolvable<A4>,
|
||||
arg5: Resolvable<A5>,
|
||||
handler: (arg1: A1, arg2: A2, arg3: A3, arg4: A4, arg5: A5) => Resolvable<R>
|
||||
): Bluebird<R>;
|
||||
|
||||
// variadic array
|
||||
/** @deprecated use .all instead */
|
||||
static join<R>(...values: Array<R | PromiseLike<R>>): Bluebird<R[]>;
|
||||
static join<R>(...values: Array<Resolvable<R>>): Bluebird<R[]>;
|
||||
|
||||
/**
|
||||
* Map an array, or a promise of an array, which contains a promises (or a mix of promises and values) with the given `mapper` function with the signature `(item, index, arrayLength)` where `item` is the resolved value of a respective promise in the input array.
|
||||
* Map an array, or a promise of an array,
|
||||
* which contains a promises (or a mix of promises and values) with the given `mapper` 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.
|
||||
*
|
||||
* If the `mapper` function returns promises or thenables, the returned promise will wait for all the mapped results to be resolved as well.
|
||||
@@ -821,28 +835,34 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
|
||||
* *The original array is not modified.*
|
||||
*/
|
||||
static map<R, U>(
|
||||
values: PromiseLike<Iterable<PromiseLike<R> | R>> | Iterable<PromiseLike<R> | R>,
|
||||
mapper: (item: R, index: number, arrayLength: number) => U | PromiseLike<U>,
|
||||
values: Resolvable<Iterable<Resolvable<R>>>,
|
||||
mapper: IterateFunction<R, 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.
|
||||
* 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.
|
||||
*
|
||||
* If the reducer function returns a promise or a thenable, the result for the promise is awaited for before continuing with next iteration.
|
||||
*
|
||||
* *The original array is not modified. If no `initialValue` is given and the array doesn't contain at least 2 items, the callback will not be called and `undefined` is returned.
|
||||
* *The original array is not modified. If no `initialValue` 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<Iterable<PromiseLike<R> | R>> | Iterable<PromiseLike<R> | R>,
|
||||
reducer: (total: U, current: R, index: number, arrayLength: number) => U | PromiseLike<U>,
|
||||
values: Resolvable<Iterable<Resolvable<R>>>,
|
||||
reducer: (total: U, current: R, index: number, arrayLength: number) => Resolvable<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.
|
||||
* 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.
|
||||
*
|
||||
* The return values from the filtered functions are coerced to booleans, with the exception of promises and thenables which are awaited for their eventual result.
|
||||
@@ -850,25 +870,28 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
|
||||
* *The original array is not modified.
|
||||
*/
|
||||
static filter<R>(
|
||||
values: PromiseLike<Iterable<PromiseLike<R> | R>> | Iterable<PromiseLike<R> | R>,
|
||||
filterer: (item: R, index: number, arrayLength: number) => boolean | PromiseLike<boolean>,
|
||||
values: Resolvable<Iterable<Resolvable<R>>>,
|
||||
filterer: IterateFunction<R, 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.
|
||||
* 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<Iterable<PromiseLike<R> | R>> | Iterable<PromiseLike<R> | R>,
|
||||
iterator: (item: R, index: number, arrayLength: number) => U | PromiseLike<U>
|
||||
static each<R>(
|
||||
values: Resolvable<Iterable<Resolvable<R>>>,
|
||||
iterator: IterateFunction<R, any>
|
||||
): 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.
|
||||
* 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.
|
||||
*
|
||||
* Returns a promise for an array that contains the values returned by the iterator function in their respective positions.
|
||||
* The iterator won't be called for an item until its previous item, and the promise returned by the iterator for that item are fulfilled.
|
||||
@@ -877,8 +900,8 @@ 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<Iterable<PromiseLike<R> | R>> | Iterable<PromiseLike<R> | R>,
|
||||
iterator: (item: R, index: number, arrayLength: number) => U | PromiseLike<U>
|
||||
values: Resolvable<Iterable<Resolvable<R>>>,
|
||||
iterator: IterateFunction<R, U>
|
||||
): Bluebird<U[]>;
|
||||
|
||||
/**
|
||||
@@ -891,7 +914,7 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
|
||||
* The second argument passed to a disposer is the result promise of the using block, which you can
|
||||
* inspect synchronously.
|
||||
*/
|
||||
disposer(disposeFn: (arg: R, promise: Bluebird<R>) => void | PromiseLike<void>): Bluebird.Disposer<R>;
|
||||
disposer(disposeFn: (arg: R, promise: Bluebird<R>) => Resolvable<void>): Bluebird.Disposer<R>;
|
||||
|
||||
/**
|
||||
* In conjunction with `.disposer`, using will make sure that no matter what, the specified disposer
|
||||
@@ -1027,7 +1050,7 @@ declare namespace Bluebird {
|
||||
/** @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]: Resolvable<T[K]>};
|
||||
|
||||
interface Resolver<R> {
|
||||
/**
|
||||
@@ -1102,7 +1125,8 @@ declare namespace Bluebird {
|
||||
/**
|
||||
* This is relevant to browser environments with no module loader.
|
||||
*
|
||||
* Release control of the Promise namespace to whatever it was before this library was loaded. Returns a reference to the library namespace so you can attach it to something else.
|
||||
* Release control of the Promise namespace to whatever it was before this library was loaded.
|
||||
* Returns a reference to the library namespace so you can attach it to something else.
|
||||
*/
|
||||
function noConflict(): typeof Bluebird;
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
@@ -20,4 +20,4 @@
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"max-line-length": [true, 280],
|
||||
"no-unnecessary-generics": false,
|
||||
"prefer-const": false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user