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

Fix (#214) : added typing for consistent return type for add() method #218

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kisshan13
Copy link

Hey I have solved the issue #214 (Allow not to copy/paste throwOnTimeout) .

I added few types like :

export type Falsy = false;
export type Truthy = true;

export type BooleanTypeReturn<
	T extends Falsy | Truthy,
	TruthyReturn,
	FalsyReturn
> = T extends Truthy ? TruthyReturn : FalsyReturn;

I used these as generic types to achieve a consistent return type based on passed parameters .

So basically what this will do is :

import Queue from "p-queue"

const queue = new Queue({
  concurrency: 1,
  interval: 1500,
  intervalCap: 1,
  throwOnTimeout: true, 
})

// typed as number
const value1 = await queue.add(async () => 123)

// typed as number
const value2 = await queue.add(async () => 123, { throwOnTimeout: true })

You can review this and tell me any changes if required.

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant