Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- interface PromiseClass<A, P extends PromiseLike<A>> {
- new(callback: (resolve: (value?: A | P) => void, reject: (reason?: any) => void) => void): P;
- }
- const bar: PromiseClass<number, Bluebird<number>> = Bluebird; // OK
- interface Options<A, P extends PromiseLike<A>, C extends PromiseClass<A, P>> {
- promise?: C;
- }
- function foo<A, P extends PromiseLike<A>, C extends PromiseClass<A, P>>(options: Options<A, P, C>) { /* empty */ }
- foo({ promise: Bluebird.resolve(3) });
- foo<number, Bluebird<number>, PromiseClass<number, Bluebird<number>>>({ promise: Bluebird.resolve(3) });
- foo<number, Bluebird<number>, PromiseClass<number, Bluebird<number>>>({ promise: Bluebird.resolve(3) });
- declare class PromisePool<
- A, // the type of value returned by the source
- P extends PromiseLike<A>, // the type of Promise returned by the source
- P2 extends PromiseLike<A>, // the type of Promise specified in `options`
- C extends PromisePool.PromiseClass<A, P2> // a helper class
- > {
- constructor(
- source: IterableIterator<P> | P | (() => (P | undefined)) | A,
- concurrency: number,
- options?: PromisePool.Options<A, P2, C>
- );
- promise(): P2;
- start(): P2;
- }
- declare namespace PromisePool {
- interface PromiseClass<A, P extends PromiseLike<A>> {
- new(callback: (resolve: (value?: A | P) => void, reject: (reason?: any) => void) => void): P;
- }
- interface Options<A, P extends PromiseLike<A>, C extends PromiseClass<A, P>> {
- promise?: C;
- }
- }
- declare class PromisePool<
- A, // the type of value returned by the source
- P extends PromiseLike<A>, // the type of Promise returned by the source
- P2 extends PromiseLike<A>, // the type of Promise specified in `options`
- C extends PromisePool.PromiseClass<A, P2> // a helper class
- > {
- constructor(
- source: IterableIterator<P> | P | (() => (P | undefined)) | A,
- concurrency: number,
- options?: PromisePool.Options<A, P2, C>
- );
- promise(): P2;
- start(): P2;
- }
- declare namespace PromisePool {
- interface PromiseClass<A, P extends PromiseLike<A>> {
- new(callback: (resolve: (value?: A | P) => void, reject: (reason?: any) => void) => void): P;
- }
- interface Options<A, P extends PromiseLike<A>, C extends PromiseClass<A, P>> {
- promise?: C;
- }
- }
Add Comment
Please, Sign In to add comment