Skip to content

fix(types): add event overloads to Cluster interface - #2201

Merged
PavelPashov merged 1 commit into
redis:mainfrom
MingLin1995:fix/cluster-event-overloads
Sep 24, 2026
Merged

PavelPashov merged 1 commit into
redis:mainfrom
MingLin1995:fix/cluster-event-overloads

Conversation

@MingLin1995

@MingLin1995 MingLin1995 commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

This pull request adds strongly-typed on and once event overloads to interface Cluster.

Background
In #2191, event listener overloads were introduced for the standalone Redis class, providing proper types for event callbacks (such as connect, ready, error, message, etc.). However, Cluster—which mixes in EventEmitter via declaration merging—still defaulted to Node.js's fallback EventEmitter.on(event: string | symbol, listener: (...args: any[]) => void), leaving callback parameters typed as any.

Changes

  • Added strongly-typed on and once method overloads to interface Cluster in lib/cluster/index.ts covering cluster events (message, messageBuffer, smessage, smessageBuffer, +node, -node, nodeError, and ClusterStatus events like connect, ready, reconnecting, close, end).
  • Added compile-time typing tests in test/typing/cluster-events.test-d.ts using tsd (expectType) to ensure callback parameters remain strictly typed and prevent future regressions.

There are no runtime behavior changes or backward-compatibility risks.


Note

Low Risk
Declaration-only TypeScript changes and compile-time tests; no runtime or API behavior changes.

Overview
Adds strongly typed on / once overloads on the merged Cluster interface so event listeners get correct callback signatures instead of generic EventEmitter any args—aligned with the standalone Redis typing from #2191.

Coverage includes pub/sub (message, messageBuffer, pmessage, smessage, etc.), cluster lifecycle (ClusterStatus), node/subscriber events (+node, -node, nodeError, refresh, …), and error. A tsd suite (test/typing/cluster-events.test-d.ts) locks in those types at compile time.

No runtime behavior changes—types and tests only.

Reviewed by Cursor Bugbot for commit 52c4b2f. Bugbot is set up for automated code reviews on this repo. Configure here.

Add strongly-typed on and once event overloads to interface Cluster for parity with Redis (introduced in redis#2191). This prevents event callback parameters from falling back to any.

- Add listener overloads for cluster events (message, messageBuffer, smessage, smessageBuffer, +node, -node, nodeError) and ClusterStatus events.

- Add tsd compile-time tests in test/typing/cluster-events.test-d.ts.
@nkaradzhov

Copy link
Copy Markdown
Contributor

Thanks, CLGTM. Let's wait for @PavelPashov for the final verdict.

@PavelPashov PavelPashov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@MingLin1995 LGTM Thank you for the contribution

@PavelPashov
PavelPashov merged commit 3996eaf into redis:main Sep 24, 2026
22 checks passed
github-actions Bot pushed a commit that referenced this pull request Oct 12, 2026
# [6.1.0-beta.1](v6.0.0...v6.1.0-beta.1) (2026-10-12)

### Bug Fixes

* accept field arrays in hmget/hmgetBuffer types ([#2167](#2167)) ([c0cd66c](c0cd66c))
* align auto-pipeline callbacks for dynamic commands ([#2180](#2180)) ([7479cab](7479cab))
* clean up Sentinel failover subscriptions after quit ([#2198](#2198)) ([727edfa](727edfa))
* cluster stuck in close ([#2217](#2217)) ([a5fad1d](a5fad1d))
* **cluster:** bucket autopipelined MSET objects by their first key ([#2207](#2207)) ([b4e3237](b4e3237))
* **cluster:** hash autopipelined Buffer keys by their bytes ([#2208](#2208)) ([a8378bd](a8378bd)), closes [Command#getSlot](https://github.com/Command/issues/getSlot)
* **cluster:** match Buffer shard channels when unsubscribing ([#2203](#2203)) ([d997d01](d997d01))
* **cluster:** support zero-argument sunsubscribe with sharded subscribers ([#2137](#2137)) ([13ff050](13ff050)), closes [#2133](#2133)
* **cluster:** vendor cluster-key-slot to fix empty hash tag slot bug ([#2172](#2172)) ([b479b76](b479b76))
* decode integer replies up to MAX_SAFE_INTEGER exactly ([#2164](#2164)) ([28940b5](28940b5))
* decode RESP3 attribute replies instead of failing the connection ([#2213](#2213)) ([6a8cb3e](6a8cb3e)), closes [#decodeNestedType](https://github.com/redis/ioredis/issues/decodeNestedType) [#decodeMapAsObject](https://github.com/redis/ioredis/issues/decodeMapAsObject) [#decodeMapKey](https://github.com/redis/ioredis/issues/decodeMapKey)
* decode RESP3 doubles with Number ([#2150](#2150)) ([6fb5a10](6fb5a10))
* handle rejections from auto-resubscribe and select on reconnect ([#2187](#2187)) ([de2fbdf](de2fbdf))
* inherit connectTimeout for cluster subscribers ([#2220](#2220)) ([db57c2d](db57c2d))
* keep String.prototype in fast mode after defining VerbatimString ([#2206](#2206)) ([90e1261](90e1261))
* keep subscriber mode while other channel kinds remain subscribed ([#2196](#2196)) ([eb97beb](eb97beb))
* keep the exec error out of its own previousErrors ([#2218](#2218)) ([2c602cf](2c602cf))
* preserve empty keys and match patterns in scan streams ([#2199](#2199)) ([b169c3a](b169c3a))
* reject unfulfilled commands dropped on reconnect ([#2194](#2194)) ([d95d05a](d95d05a)), closes [#2193](#2193)
* reset retry attempts when connect() is called after giving up ([#2204](#2204)) ([b597303](b597303)), closes [#1463](#1463)
* **types:** accept documented TLS profile options ([#2195](#2195)) ([56a7fb8](56a7fb8)), closes [#1626](#1626)
* **types:** add event overloads to Cluster interface ([#2201](#2201)) ([3996eaf](3996eaf)), closes [#2191](#2191)
* **types:** add smessage and smessageBuffer event overloads ([#2191](#2191)) ([ee48f4c](ee48f4c)), closes [#2190](#2190)
* **types:** allow number for zrange stop argument ([#2163](#2163)) ([932f4c2](932f4c2))

### Features

* bless commands ([#2209](#2209)) ([9181ee0](9181ee0))
* **cluster:** allow configuring node role for Pub/Sub subscriber ([#2176](#2176)) ([6b9130c](6b9130c))
* smart client handoffs ([#2165](#2165)) ([d8ae3cb](d8ae3cb))
github-actions Bot pushed a commit that referenced this pull request Oct 12, 2026
# [6.1.0-beta.1](v6.0.0...v6.1.0-beta.1) (2026-10-12)

### Bug Fixes

* accept field arrays in hmget/hmgetBuffer types ([#2167](#2167)) ([c0cd66c](c0cd66c))
* align auto-pipeline callbacks for dynamic commands ([#2180](#2180)) ([7479cab](7479cab))
* clean up Sentinel failover subscriptions after quit ([#2198](#2198)) ([727edfa](727edfa))
* cluster stuck in close ([#2217](#2217)) ([a5fad1d](a5fad1d))
* **cluster:** bucket autopipelined MSET objects by their first key ([#2207](#2207)) ([b4e3237](b4e3237))
* **cluster:** hash autopipelined Buffer keys by their bytes ([#2208](#2208)) ([a8378bd](a8378bd)), closes [Command#getSlot](https://github.com/Command/issues/getSlot)
* **cluster:** match Buffer shard channels when unsubscribing ([#2203](#2203)) ([d997d01](d997d01))
* **cluster:** support zero-argument sunsubscribe with sharded subscribers ([#2137](#2137)) ([13ff050](13ff050)), closes [#2133](#2133)
* **cluster:** vendor cluster-key-slot to fix empty hash tag slot bug ([#2172](#2172)) ([b479b76](b479b76))
* decode integer replies up to MAX_SAFE_INTEGER exactly ([#2164](#2164)) ([28940b5](28940b5))
* decode RESP3 attribute replies instead of failing the connection ([#2213](#2213)) ([6a8cb3e](6a8cb3e)), closes [#decodeNestedType](https://github.com/redis/ioredis/issues/decodeNestedType) [#decodeMapAsObject](https://github.com/redis/ioredis/issues/decodeMapAsObject) [#decodeMapKey](https://github.com/redis/ioredis/issues/decodeMapKey)
* decode RESP3 doubles with Number ([#2150](#2150)) ([6fb5a10](6fb5a10))
* handle rejections from auto-resubscribe and select on reconnect ([#2187](#2187)) ([de2fbdf](de2fbdf))
* inherit connectTimeout for cluster subscribers ([#2220](#2220)) ([db57c2d](db57c2d))
* keep String.prototype in fast mode after defining VerbatimString ([#2206](#2206)) ([90e1261](90e1261))
* keep subscriber mode while other channel kinds remain subscribed ([#2196](#2196)) ([eb97beb](eb97beb))
* keep the exec error out of its own previousErrors ([#2218](#2218)) ([2c602cf](2c602cf))
* preserve empty keys and match patterns in scan streams ([#2199](#2199)) ([b169c3a](b169c3a))
* reject unfulfilled commands dropped on reconnect ([#2194](#2194)) ([d95d05a](d95d05a)), closes [#2193](#2193)
* reset retry attempts when connect() is called after giving up ([#2204](#2204)) ([b597303](b597303)), closes [#1463](#1463)
* **types:** accept documented TLS profile options ([#2195](#2195)) ([56a7fb8](56a7fb8)), closes [#1626](#1626)
* **types:** add event overloads to Cluster interface ([#2201](#2201)) ([3996eaf](3996eaf)), closes [#2191](#2191)
* **types:** add smessage and smessageBuffer event overloads ([#2191](#2191)) ([ee48f4c](ee48f4c)), closes [#2190](#2190)
* **types:** allow number for zrange stop argument ([#2163](#2163)) ([932f4c2](932f4c2))

### Features

* bless commands ([#2209](#2209)) ([9181ee0](9181ee0))
* **cluster:** allow configuring node role for Pub/Sub subscriber ([#2176](#2176)) ([6b9130c](6b9130c))
* smart client handoffs ([#2165](#2165)) ([d8ae3cb](d8ae3cb))
github-actions Bot pushed a commit that referenced this pull request Oct 12, 2026
# [6.1.0-beta.1](v6.0.0...v6.1.0-beta.1) (2026-10-12)

### Bug Fixes

* accept field arrays in hmget/hmgetBuffer types ([#2167](#2167)) ([c0cd66c](c0cd66c))
* align auto-pipeline callbacks for dynamic commands ([#2180](#2180)) ([7479cab](7479cab))
* clean up Sentinel failover subscriptions after quit ([#2198](#2198)) ([727edfa](727edfa))
* cluster stuck in close ([#2217](#2217)) ([a5fad1d](a5fad1d))
* **cluster:** bucket autopipelined MSET objects by their first key ([#2207](#2207)) ([b4e3237](b4e3237))
* **cluster:** hash autopipelined Buffer keys by their bytes ([#2208](#2208)) ([a8378bd](a8378bd)), closes [Command#getSlot](https://github.com/Command/issues/getSlot)
* **cluster:** match Buffer shard channels when unsubscribing ([#2203](#2203)) ([d997d01](d997d01))
* **cluster:** support zero-argument sunsubscribe with sharded subscribers ([#2137](#2137)) ([13ff050](13ff050)), closes [#2133](#2133)
* **cluster:** vendor cluster-key-slot to fix empty hash tag slot bug ([#2172](#2172)) ([b479b76](b479b76))
* decode integer replies up to MAX_SAFE_INTEGER exactly ([#2164](#2164)) ([28940b5](28940b5))
* decode RESP3 attribute replies instead of failing the connection ([#2213](#2213)) ([6a8cb3e](6a8cb3e)), closes [#decodeNestedType](https://github.com/redis/ioredis/issues/decodeNestedType) [#decodeMapAsObject](https://github.com/redis/ioredis/issues/decodeMapAsObject) [#decodeMapKey](https://github.com/redis/ioredis/issues/decodeMapKey)
* decode RESP3 doubles with Number ([#2150](#2150)) ([6fb5a10](6fb5a10))
* handle rejections from auto-resubscribe and select on reconnect ([#2187](#2187)) ([de2fbdf](de2fbdf))
* inherit connectTimeout for cluster subscribers ([#2220](#2220)) ([db57c2d](db57c2d))
* keep String.prototype in fast mode after defining VerbatimString ([#2206](#2206)) ([90e1261](90e1261))
* keep subscriber mode while other channel kinds remain subscribed ([#2196](#2196)) ([eb97beb](eb97beb))
* keep the exec error out of its own previousErrors ([#2218](#2218)) ([2c602cf](2c602cf))
* preserve empty keys and match patterns in scan streams ([#2199](#2199)) ([b169c3a](b169c3a))
* reject unfulfilled commands dropped on reconnect ([#2194](#2194)) ([d95d05a](d95d05a)), closes [#2193](#2193)
* reset retry attempts when connect() is called after giving up ([#2204](#2204)) ([b597303](b597303)), closes [#1463](#1463)
* **types:** accept documented TLS profile options ([#2195](#2195)) ([56a7fb8](56a7fb8)), closes [#1626](#1626)
* **types:** add event overloads to Cluster interface ([#2201](#2201)) ([3996eaf](3996eaf)), closes [#2191](#2191)
* **types:** add smessage and smessageBuffer event overloads ([#2191](#2191)) ([ee48f4c](ee48f4c)), closes [#2190](#2190)
* **types:** allow number for zrange stop argument ([#2163](#2163)) ([932f4c2](932f4c2))

### Features

* bless commands ([#2209](#2209)) ([9181ee0](9181ee0))
* **cluster:** allow configuring node role for Pub/Sub subscriber ([#2176](#2176)) ([6b9130c](6b9130c))
* smart client handoffs ([#2165](#2165)) ([d8ae3cb](d8ae3cb))
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 6.1.0-beta.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants