p-queue
p-queue copied to clipboard
Fix timeout-dependent return types of `add` and `addAll`
Hi. The return types of add
and addAll
are currently a bit funky. I think there was a regression.
For example, the following code raises a type error for b
because it thinks a
is number | void
:
const a = await this.queue.add(async () => 1);
const b: number = a * 2;
That doesn't seem right. It should only return number | void
when both timeout=number
and throwOnTimeout=false|undefined
. But in the example above I haven't even specified timeout
, so the void
behavior should never surface.
This PR fixes the return types:
- When
timeout=number
andthrowOnTimeout=true
, return type isThing
. - When
timeout=number
andthrowOnTimeout=false|undefined
, return type isThing | void
. - When
timeout=undefined
andthrowOnTimeout=true|false|undefined
, return type isThing
.
To further emphasize the relationship between timeout
and throwOnTimeout
I also added a note in the readme and a warning message in the console.