`RedisClientOptions` default RESP generic conflicts with default `RedisClientType` in redis@6
Description
After upgrading to [email protected], annotating client options with the exported
RedisClientOptions type causes createClient(options) to infer a client whose
RESP generic is RespVersions (2 | 3).
That inferred client cannot be returned or assigned as the default exported
RedisClientType, because RedisClientType defaults the RESP generic to 3.
This fails with exactOptionalPropertyTypes: true.
Minimal Reproduction
import { createClient, type RedisClientOptions, type RedisClientType } from "redis";
function buildOptions(): RedisClientOptions {
return {
url: "redis://localhost:6379",
};
}
export async function createRedisClient(): Promise<RedisClientType> {
const options = buildOptions();
const client = createClient(options);
await client.connect();
return client;
}
Actual Error
Type 'RedisClientType<RedisModules, RedisFunctions, RedisScripts, RespVersions, TypeMapping>' is not assignable to type 'RedisClientType' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
Type 'RedisClientType<RedisModules, RedisFunctions, RedisScripts, RespVersions, TypeMapping>' is not assignable to type 'RedisClient<RedisDefaultModules, {}, {}, 3, {}>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
Types of property 'options' are incompatible.
Type 'RedisClientOptions<RedisDefaultModules & RedisModules, RedisFunctions, RedisScripts, RespVersions, TypeMapping, RedisSocketOptions>' is not assignable to type 'RedisClientOptions<RedisDefaultModules, {}, {}, 3, TypeMapping, RedisSocketOptions>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
Type 'RespVersions' is not assignable to type '3'.
Type '2' is not assignable to type '3'.ts(2375)
Expected Behavior
Using the exported RedisClientOptions type should not make createClient(options)
infer a client that is incompatible with the exported default RedisClientType.
Either RedisClientOptions should default its RESP generic consistently with
RedisClientType, or there should be an exported options type that represents
the default createClient() / RedisClientType shape in redis@6.
Why This Is Confusing
RedisClientType defaults to RESP 3:
RedisClientType<{}, {}, {}, 3, {}>
But RedisClientOptions defaults to the broader RESP union:
RedisClientOptions<RedisModules, RedisFunctions, RedisScripts, RespVersions, TypeMapping>
Because RespVersions includes 2, the client inferred from annotated options
is not assignable to the default RedisClientType.
Environment
redis:6.0.0typescript: 6.0.3node: 24.16exactOptionalPropertyTypes:true
Node.js Version
24.16
Redis Server Version
redis:8.6-alpine
Node Redis Version
6.0.0
Platform
WSL2 - Ubuntu 24.04
Logs
Thanks @adcuelloa i will have a look