fix(events): type completed event returnvalue as deserialized value - #4441
fix(events): type completed event returnvalue as deserialized value#4441toufiq-dev wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR corrects the TypeScript typing for the QueueEvents "completed" event so that returnvalue is typed as the deserialized processor return value (matching the runtime behavior where queue-events.ts does JSON.parse before emitting).
Changes:
- Made
QueueEventsListenergeneric (<ReturnType = any>) and updated the"completed"event signature to useReturnType. - Made
QueueEventsgeneric (QueueEvents<ReturnType = any>) and threaded the type parameter throughemit/on/once/off. - Added a regression test to assert
"completed"emits an object return value as an object (not a string), and updated NestJS docs examples accordingly.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
tests/events.test.ts |
Adds a regression test verifying the "completed" event delivers a deserialized (object) returnvalue. |
src/classes/queue-events.ts |
Updates listener and class typings to make "completed".returnvalue generic and aligned with runtime JSON parsing. |
docs/gitbook/guide/nestjs/queue-events-listeners.md |
Updates NestJS guide example to avoid claiming returnvalue is a string. |
docs/gitbook/bullmq-pro/nestjs/queue-events-listeners.md |
Same documentation correction for the BullMQ Pro NestJS guide. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Heads up on CI: the single failing check ( |
94e9f0b to
255c2bd
Compare
255c2bd to
d91f756
Compare
|
Thanks for the review @manast! I checked all four runtimes in the monorepo to verify whether the same issue needs porting:
So my take: this fix is correctly Node/TypeScript-only. The other runtimes either already deserialize (Python) or genuinely deliver a string with matching types (Rust/Elixir), and PHP has no global events API yet. Happy to open follow-up issues for Rust/Elixir parse parity if you would like. |
d91f756 to
8dc6a10
Compare
8dc6a10 to
2b47467
Compare
|
Hi @manast quick heads-up: the 9 CI workflows on this PR are sitting in 'awaiting approval' (they were triggered when the branch was last pushed, but never ran). Since it's a fork PR, only a maintainer can approve them. Could you 'Approve and run' on the checks when you get a chance? Once they pass, it should be ready to merge. Thanks! |
841f143 to
55c82c9
Compare
55c82c9 to
00f9da1
Compare
Summary
Closes #4147
This PR fixes the
completedevent typing onQueueEvents. At runtime,queue-events.tsdeserializes the job return value withJSON.parsebefore emitting it to listeners, so thereturnvaluereceived by event handlers is the actual processor return value (object, number, boolean, etc.) — not the string it was previously typed as.Changes
QueueEventsListenergeneric with aReturnType = anytype parameter (mirroring the existingMinimalJob<DataType, ReturnType>/WorkerListenerconventions).completedevent asargs: { jobId: string; returnvalue: ReturnType; prev?: string }.QueueEventsclass generic (QueueEvents<ReturnType = any>) and thread the type parameter throughemit/off/on/once.completedto reflect thatreturnvalueis deserialized from JSON.returnvalue: string.Usage
Tests
tests/events.test.ts(emits completed global event with the deserialized return value) that processes a job returning an object and asserts thecompletedevent delivers the deserialized object.tests/events.test.tspass.tsc,eslint, andprettierare clean.