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

Improving queue type on processor to avoid casting #394

Merged
merged 3 commits into from
Dec 2, 2024

Conversation

CarlosGamero
Copy link
Collaborator

@CarlosGamero CarlosGamero commented Nov 26, 2024

Changes

Checklist

  • Apply one of following labels; major, minor, patch or skip-release
  • I've updated the documentation, or no changes were necessary
  • I've updated the tests, or no changes were necessary

@CarlosGamero CarlosGamero self-assigned this Nov 26, 2024
Comment on lines -44 to +51
QueueType extends Queue<JobPayload, JobReturn> = Queue<JobPayload, JobReturn>,
QueueType extends Queue<JobPayload, JobReturn, string, JobPayload, JobReturn, string> = Queue<
JobPayload,
JobReturn,
string,
JobPayload,
JobReturn,
string
>,
Copy link
Collaborator Author

@CarlosGamero CarlosGamero Nov 26, 2024

Choose a reason for hiding this comment

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

As JobPayload is not defined at this stage, TS can't infer NameType

export declare class Queue<..., DefaultNameType extends string = string, ..., NameType extends string = ExtractNameType<DataTypeOrJob, DefaultNameType>> {

type ExtractNameType<DataTypeOrJob, Default extends string> = DataTypeOrJob extends Job<any, any, infer N> ? N : Default;

So trying to define it explicitly to help TS

@CarlosGamero CarlosGamero marked this pull request as ready for review December 2, 2024 15:16
@CarlosGamero
Copy link
Collaborator Author

I tested it locally by linking AP to this version of the library and looks like it is working with BullMqPro so I think it should be fine

Copy link
Collaborator

@kibertoad kibertoad left a comment

Choose a reason for hiding this comment

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

fantastic work, Carlos, thank you!

@CarlosGamero CarlosGamero merged commit 1e852ef into main Dec 2, 2024
5 checks passed
@CarlosGamero CarlosGamero deleted the improve_queue_type branch December 2, 2024 16:25
@CarlosGamero CarlosGamero changed the title Improving queue type on processor to avoid any casting Improving queue type on processor to avoid casting Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants