sindresorhus / p-queue

Promise queue with concurrency control

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`PQueue.on` does not exist

AzureFlow opened this issue · comments

commented

It appears like on isn't working, at least on ^7.3.4. I saw #153 but it doesn't appear like there a resolution to the problem.

Given the following example:

import PQueue from "p-queue";

const queue = new PQueue({concurrency: 1});
queue.on("add", () => {
    console.log(`Task is added.  Size: ${queue.size}  Pending: ${queue.pending}`);
});

let count = 0;
(async () => {
    await queue.add(() => {
        console.log("Start #1");

        return new Promise((resolve) => setTimeout(resolve, 5 * 1000));
    });

    console.log("Done #1");
})();

It results in:

TS2339: Property 'on' does not exist on type 'PQueue '.

Thanks.

We have tests that confirm it's working:

queue.on('active', () => {

It exists, however it appears to be missing from the type def.

async #onEvent(event: EventName, filter?: () => boolean): Promise<void> {

I am also facing the same issue on v7 (queue.on doesnot exists);

commented

Apparently this is caused by not having the script included in your tsconfig.json's include array.

Still facing the same issue, I have includes in my tsconfig.json.

Still facing the same issue, I have includes in my tsconfig.json.

It worked for me, just make sure you are using the d.ts file
"include": ["node_modules/p-queue/dist/index.d.ts"]

Yes but we don't have to do this, this is the package.json of this project that have to do this