mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-09 11:40:07 +00:00
Restore covariant comparison to bluebird's Promise
Now that typescript@next checks variance more strictly for conditional types, bluebird's Promise is invariant. This PR removes conditional types from bluebird so that Promise compares covariantly again. Note that I never figured out how to do this for `call`, so it returns `Bluebird<any>` right now. I'm still working on that.
This commit is contained in:
46
types/bluebird/index.d.ts
vendored
46
types/bluebird/index.d.ts
vendored
@@ -37,8 +37,6 @@
|
||||
|
||||
type Constructor<E> = new (...args: any[]) => E;
|
||||
type CatchFilter<E> = ((error: E) => boolean) | (object & E);
|
||||
type IterableItem<R> = R extends Iterable<infer U> ? U : 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>;
|
||||
|
||||
@@ -352,7 +350,7 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
|
||||
* });
|
||||
* </code>
|
||||
*/
|
||||
call<U extends keyof R>(propertyName: U, ...args: any[]): Bluebird<R[U] extends (...args: any[]) => any ? ReturnType<R[U]> : never>;
|
||||
call<U extends keyof R>(propertyName: U, ...args: any[]): Bluebird<any>;
|
||||
|
||||
/**
|
||||
* This is a convenience method for doing:
|
||||
@@ -562,12 +560,17 @@ 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>>) => Resolvable<U>): Bluebird<U>;
|
||||
spread<U, Q>(this: Bluebird<R & Iterable<Q>>, fulfilledHandler: (...values: Array<Q>) => 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.
|
||||
*/
|
||||
all(): Bluebird<IterableOrNever<R>>;
|
||||
all(this: Bluebird<Iterable<unknown>>): Bluebird<R>;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
all(): Bluebird<never>;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@@ -578,42 +581,59 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
|
||||
/**
|
||||
* Same as calling `Promise.any(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
|
||||
*/
|
||||
any(): Bluebird<IterableItem<R>>;
|
||||
any<Q>(this: Bluebird<R & Iterable<Q>>): Bluebird<Q>;
|
||||
|
||||
/**
|
||||
* Same as calling `Promise.any(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
|
||||
*/
|
||||
any(): Bluebird<never>;
|
||||
|
||||
/**
|
||||
* Same as calling `Promise.some(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
|
||||
* Same as calling `Promise.some(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
|
||||
*/
|
||||
some(count: number): Bluebird<IterableOrNever<R>>;
|
||||
some(this: Bluebird<Iterable<unknown>>, count: number): Bluebird<R>;
|
||||
|
||||
/**
|
||||
* Same as calling `Promise.some(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
|
||||
* Same as calling `Promise.some(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
|
||||
*/
|
||||
some(count: number): Bluebird<never>;
|
||||
|
||||
/**
|
||||
* Same as calling `Promise.race(thisPromise, count)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
|
||||
*/
|
||||
race(): Bluebird<IterableItem<R>>;
|
||||
race<Q>(this: Bluebird<R & Iterable<Q>>): Bluebird<Q>;
|
||||
|
||||
/**
|
||||
* Same as calling `Promise.race(thisPromise, count)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
|
||||
*/
|
||||
race(): Bluebird<never>;
|
||||
|
||||
/**
|
||||
* 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: IterateFunction<IterableItem<R>, U>, options?: Bluebird.ConcurrencyOption): Bluebird<R extends Iterable<any> ? U[] : never>;
|
||||
map<U, Q>(this: Bluebird<R & Iterable<Q>>, mapper: IterateFunction<Q, U>, options?: Bluebird.ConcurrencyOption): Bluebird<U[]>;
|
||||
|
||||
/**
|
||||
* 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) => Resolvable<U>, initialValue?: U): Bluebird<R extends Iterable<any> ? U : never>;
|
||||
reduce<U, Q>(this: Bluebird<R & Iterable<Q>>, reducer: (memo: U, item: Q, index: number, arrayLength: number) => Resolvable<U>, initialValue?: U): Bluebird<U>;
|
||||
|
||||
/**
|
||||
* 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: IterateFunction<IterableItem<R>, boolean>, options?: Bluebird.ConcurrencyOption): Bluebird<IterableOrNever<R>>;
|
||||
filter<Q>(this: Bluebird<R & Iterable<Q>>, filterer: IterateFunction<Q, boolean>, options?: Bluebird.ConcurrencyOption): Bluebird<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(iterator: IterateFunction<IterableItem<R>, any>): Bluebird<IterableOrNever<R>>;
|
||||
each<Q>(this: Bluebird<R & Iterable<Q>>, iterator: IterateFunction<Q, any>): Bluebird<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: IterateFunction<IterableItem<R>, U>): Bluebird<R extends Iterable<any> ? U[] : never>;
|
||||
mapSeries<U, Q>(this: Bluebird<R & Iterable<Q>>, iterator: IterateFunction<Q, U>): Bluebird<U[]>;
|
||||
|
||||
/**
|
||||
* Cancel this `promise`. Will not do anything if this promise is already settled or if the cancellation feature has not been enabled
|
||||
|
||||
Reference in New Issue
Block a user