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
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.

3 participants