Skip to content

fix(client): align RedisClientOptions RESP default with RedisClientType - #3303

Merged
nkaradzhov merged 3 commits into
redis:masterfrom
nytheradev:fix/redis-client-options-resp-default-3300
Jun 1, 2026
Merged

nkaradzhov merged 3 commits into
redis:masterfrom
nytheradev:fix/redis-client-options-resp-default-3300

Conversation

@nytheradev

@nytheradev nytheradev commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Default RedisClientOptions RESP generic to 3, matching RedisClientType, createClient, and RedisClient.create.
  • Apply the same default for RedisClusterOptions and RedisSentinelOptions.
  • Use explicit RespVersions in internal code that must accept RESP2 clients.
  • Add compile-time regression test (npm run test:types in @redis/client).

Test plan

  • npm run test:types in packages/client
  • npx tsc --build in packages/client
  • Full npm test in CI

Fixes #3300


Note

Low Risk
Type-level defaults and internal widening only; runtime behavior unchanged except consumers see stricter/narrower typings aligned with existing factory defaults.

Overview
Fixes #3300 by aligning public *Options interfaces with their matching *Type aliases and factories on RESP3 as the default.

RedisClientOptions, RedisClusterOptions, and RedisSentinelOptions (and related node option types) now default the RESP generic to 3 instead of the full RespVersions union, matching RedisClientType, createClient, and cluster/sentinel factories. That restores patterns like function f(opts: RedisClientOptions): RedisClientType when options are passed into createClient.

A new exported AnyRedisClientOptions widens RESP to RespVersions for internal paths that must accept any protocol version (URL parsing, maintenance manager, sentinel #createClient, pub-sub proxy, test-utils ACL cleanup).

npm run test:types runs compile-only checks under types-tests/ (RESP default parity and the standalone factory return-type pattern); test in @redis/client invokes it before Mocha.

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

RedisClientOptions defaulted RESP to RespVersions (2 | 3) while RedisClientType and createClient default to 3. Annotating options with RedisClientOptions caused createClient(options) to return a client incompatible with RedisClientType, especially with exactOptionalPropertyTypes.

Fixes redis#3300

Co-authored-by: Cursor <cursoragent@cursor.com>
@jit-ci

jit-ci Bot commented Jun 1, 2026

Copy link
Copy Markdown

Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset.

In case there are security findings, they will be communicated to you as a comment inside the PR.

Hope you’ll enjoy using Jit.

Questions? Comments? Want to learn more? Get in touch with us.

@nytheradev

Copy link
Copy Markdown
Contributor Author

Hello, I checked the issue and investigated the relevant method. I would like to take this up and submit a fix. Could you assign it to me?

… test

Applied on top of redis#3303 to address review findings:

* `packages/test-utils/lib/index.ts` — `cleanupAclUsers` parameter was
  `Partial<RedisClientOptions>`, which after redis#3303 narrows `RESP` to `3`.
  Internal callers pass `Partial<RedisClientOptions<M, F, S, RESP, ...>>`
  with the test's generic `RESP`, breaking the monorepo `tsc --build`.
  Widen to `Partial<RedisClientOptions<RedisModules, RedisFunctions,
  RedisScripts, RespVersions>>` so any `RESP` literal is accepted, as
  done for other internal RESP-erased call sites in redis#3303.

* `enterprise-maintenance-manager.ts` — `import` / `type` / `import`
  ordering swapped to a clean import block followed by the local
  `AnyRedisClientOptions` alias. TS-valid either way; just less
  surprising for readers.

* `create-client.types-test.ts` — broaden the regression. The original
  test only validated standalone (`RedisClientType` / `RedisClientOptions`).
  Add `Equal<…>`-style RESP-default parity assertions for cluster,
  sentinel, and pool so any future drift on those `*Options` interfaces
  fails compile. The function-signature pattern (`function f(opts: X):
  Y { return create(opts); }`) is still exercised for standalone and
  pool. Cluster and sentinel are explicitly omitted from that pattern
  because their `*Options` interfaces default `M`/`F`/`S` to
  `RedisModules`/`RedisFunctions`/`RedisScripts` (wide) while the
  `*Type` aliases default them to `{}` (narrow) — an asymmetry that is
  independent of redis#3300 and surfaces a separate `M`-invariance in cluster
  through `_handleAsk`. Captured in a comment so the next reader does
  not try to re-add those tests blind.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 0c7ad14. Configure here.

- Move types-test out of `lib/` to `packages/client/types-tests/` so it is
  not compiled into `dist/` by the production build or picked up by typedoc.
- Make parity assertions actually fail on drift: strict `Equal` returning
  `true | false` (never `never`), wrapped in `Assert<T extends true>`. The
  previous `Equal<…, …>` returned `never` on mismatch, which `Assert<never>`
  would accept vacuously. Switched extraction to `infer` on every generic
  position so invariant generics (cluster) don't collapse the conditional
  to `never`. Each side now asserts against the literal `3` independently.
- Dedupe the widened `RedisClientOptions` alias: export `AnyRedisClientOptions`
  from `lib/client` (replacing the private `ParsedRedisClientOptions` and the
  inline duplicates in `enterprise-maintenance-manager.ts`, `sentinel/index.ts`,
  `sentinel/pub-sub-proxy.ts`, and `test-utils`).
- Restore `parseOptions` identity generic so caller-side narrowing (incl.
  `SocketOptions`) is preserved end-to-end:
  `static parseOptions<O extends AnyRedisClientOptions>(options: O): O`.
@nkaradzhov
nkaradzhov merged commit cc446ad into redis:master Jun 1, 2026
14 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.

RedisClientOptions default RESP generic conflicts with default RedisClientType in redis@6

2 participants