Skip to content

Fix TypeScript callback type for AMQPConsumer subscribe method to support async callbacks#155

Merged
baelter merged 1 commit intomainfrom
copilot/fix-sonarlint-typeerror-amqpconsumer
Sep 9, 2025
Merged

Fix TypeScript callback type for AMQPConsumer subscribe method to support async callbacks#155
baelter merged 1 commit intomainfrom
copilot/fix-sonarlint-typeerror-amqpconsumer

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Sep 9, 2025

The TypeScript type definitions for the subscribe callback were too restrictive, only allowing synchronous callbacks that return void. This caused SonarLint to throw warnings when using async callbacks as shown in the README example:

const consumer = await q.subscribe({noAck: true}, async (msg) => {
  console.log(msg.bodyToString())
  await consumer.cancel()
})

The warning was:

Promise returned in function argument where a void return was expected.sonarlint(typescript:S6544)

However, the runtime already supports async callbacks - this was confirmed by existing tests that use async callbacks successfully. The issue was purely in the TypeScript type definitions being overly restrictive.

This PR updates the callback type signature from (msg: AMQPMessage) => void to (msg: AMQPMessage) => void | Promise<void> in:

  • src/amqp-queue.ts - subscribe method
  • src/amqp-channel.ts - basicConsume method
  • src/amqp-consumer.ts - constructor and onMessage property

The change is minimal and surgical, only updating type signatures to match the actual runtime behavior. No functional code changes were required. This maintains full backward compatibility with existing synchronous callbacks while properly supporting asynchronous ones.

After this change, the README example and any other code using async callbacks in subscribe methods will compile without TypeScript/SonarLint warnings.

Fixes #92.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Sonarlint throwing a TypeError warning for AMQPConsumer / q.subscribe using example on README Fix TypeScript callback type for AMQPConsumer subscribe method to support async callbacks Sep 9, 2025
Copilot AI requested a review from baelter September 9, 2025 11:38
Co-authored-by: baelter <1399369+baelter@users.noreply.github.com>
@baelter baelter force-pushed the copilot/fix-sonarlint-typeerror-amqpconsumer branch from aae210f to ca5b1db Compare September 9, 2025 12:11
@baelter baelter marked this pull request as ready for review September 9, 2025 12:11
@baelter baelter merged commit 6bb1325 into main Sep 9, 2025
6 checks passed
@baelter baelter deleted the copilot/fix-sonarlint-typeerror-amqpconsumer branch September 9, 2025 12:13
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.

Sonarlint throwing a TypeError warning for AMQPConsumer / q.subscribe using example on README

2 participants