Skip to content

fix(types): add smessage and smessageBuffer event overloads - #2191

Merged
PavelPashov merged 1 commit into
redis:mainfrom
ramin-010:fix/smessage-event-types
Sep 10, 2026
Merged

PavelPashov merged 1 commit into
redis:mainfrom
ramin-010:fix/smessage-event-types

Conversation

@ramin-010

@ramin-010 ramin-010 commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2190.

Adds smessage and smessageBuffer overloads for on and once, with
assertions for both callback parameter types.

Without the overloads npm run test:tsd reports 8 errors of the form
"not identical to argument type any"; with them it passes.

Also renames events.test-.ts to events.test-d.ts for consistency with the
other files in that directory — as you noted, tsd already collects it, so this
activates nothing.


Note

Low Risk
Type-only changes and typing tests; no runtime subscriber or emit behavior is modified.

Overview
Adds TypeScript event overloads on Redis for on/once when listening to smessage and smessageBuffer, matching the existing message / pmessage patterns (string vs Buffer channel and payload).

Extends test/typing/events.test-d.ts with tsd assertions so subscriber callbacks for those events are typed as string or Buffer instead of falling through to any and failing test:tsd.

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

DataHandler emits smessage and smessageBuffer for sharded pub/sub, but the
on/once overloads on Redis only covered message, messageBuffer, pmessage and
pmessageBuffer, so both callback parameters came through as any.

Add the two overload pairs with assertions for both parameter types, and
rename events.test-.ts to match the surrounding files.

Closes redis#2190

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

Looks good, thank you for the contribution.

@PavelPashov
PavelPashov merged commit ee48f4c into redis:main Sep 10, 2026
22 checks passed
PavelPashov pushed a commit that referenced this pull request Sep 24, 2026
Add strongly-typed on and once event overloads to interface Cluster for parity with Redis (introduced in #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.
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.

smessage and smessageBuffer are not typed on Redis#on / Redis#once

2 participants