sindresorhus / p-queue

Promise queue with concurrency control
MIT License
3.39k stars 182 forks source link

`PQueue.on` does not exist #192

Closed AzureFlow closed 1 year ago

AzureFlow commented 1 year ago

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.

sindresorhus commented 1 year ago

We have tests that confirm it's working: https://github.com/sindresorhus/p-queue/blob/c12ec2e10c99698862b6d03ce28bc54e4bb02fdc/test/test.ts#L844

darinw commented 1 year ago

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

https://github.com/sindresorhus/p-queue/blob/c12ec2e10c99698862b6d03ce28bc54e4bb02fdc/source/index.ts#L386

himansusekhar11004 commented 1 year ago

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

AzureFlow commented 1 year ago

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

himansusekhar11004 commented 1 year ago

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

darinw commented 1 year ago

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"]

yovanoc commented 12 months ago

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