Skip to content

[Bug] (Pro): Weak type inference on QueuePro type #3438

@gabrielmeloc22

Description

@gabrielmeloc22

Version

v7.38.5

Platform

NodeJS

What happened?

At my work we've just got the BullMQ Pro license and I've been migrating the codebase to use the types from the pro npm package. However I ran into a quite annoying issue, seems like even though the QueuePro does extend the Queue type, it does not have the same generic inference as the base queue type.

Queue type:
https://github.com/taskforcesh/bullmq/blob/master/src/classes/queue.ts#L153

QueuePro type

export declare class QueuePro<DataType = any, ReturnType = any, NameType extends string = string> extends Queue<DataType, ReturnType, NameType> {
....

The type above makes it not possible to pass a Job union as the first generic argument and have a strong typed queue.add method like the base type has.

Example that works with the base Queue type

type MyJobs = Job<number, void, 'job1'> | Job<boolean, void, 'job2'>

type MyQueue = Queue<MyJobs>

const myQueue: MyQueue = new Queue('my-queue')

myQueue.add('job1', 10) // works
myQueue.add('job2', true) // works

myQueue.add('job1', 'hello') // should not work
myQueue.add('job1', 10) // should not work

Instead what happens is that it does not accept the job union and creates a typescript error because it only accepts a data type:

Diagnostics:
1. Argument of type 'JobData' is not assignable to parameter of type 'JobUnion'.
     Type '{ id: string; }' is not assignable to type 'JobUnion'. [2345]

How to reproduce.

1. Declare a job union

type MyJobs = JobPro<number, void, 'job1'> | JobPro<boolean, void, 'job2'>

2. Declare a queue type using the union

type MyQueue = QueuePro<MyJobs>

const myQueue: MyQueue = new QueuePro('my-queue')

3. Use queue.add

type MyQueue = QueuePro<MyJobs>

myQueue.add('job1', 10) // should raise mentioned ts error

Relevant log output

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions