Skip to content

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

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

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.

@kisshan13
Copy link
Author

Hey have you guys reviewed my pr ?

Copy link

@Seally Seally left a comment

Choose a reason for hiding this comment

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

I'm not one of the repo's maintainers, but this PR shouldn't drastically change the code style. Most, if not all, of the lint failures are formatting issues. It also creates a lot of noise in the diffs, making it difficult to review.

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.

2 participants