Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add typings that work with current TS version #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions es6-promise-pool.d.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
interface Options<A> {
promise?: PromiseLike<A>
}
// fix 2018-01-08

export = PromisePool

declare class PromisePool<A> extends EventTarget {
constructor(
source: () => PromiseLike<A>|void,
concurrency: number,
options?: Options<A>
)
concurrency(concurrency: number): number
size(): number
active(): boolean
promise(): PromiseLike<A>
start(): PromiseLike<A>
// skip GeneratorFunction as that is documented to be deprecated starting v3
constructor(
source: IterableIterator<Promise<A>> | Promise<A> | (() => (Promise<A> | void)) | A,
concurrency: number,
options?: PromisePool.Options<A>
)

concurrency(concurrency: number): number
size(): number
active(): boolean
promise(): PromiseLike<A>
start(): PromiseLike<A>
}

export default PromisePool
declare namespace PromisePool {
export interface Options<A> {
promise?: Promise<A>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This indicates that promise is an instance of Promise, whereas what it should be is a function that can produce a PromiseLike. I adapted a definition from Bluebird:

declare namespace PromisePool {
    interface PromiseFunction<A> {
        new(callback: (resolve: (value?: A) => void, reject: (reason?: any) => void) => void): PromiseLike<A>;
    }

    export interface Options<A> {
        promise?: PromiseFunction<A>
    }
}

Which made this work:

import PromisePool = require("es6-promise-pool");
import Bluebird = require("bluebird");

const options = { promise: Bluebird };
const pool = new PromisePool("test", 1, options);

const options2 = { promise: Promise };
const pool2 = new PromisePool("test", 1, options2);

}
}