Skip to content

RedisClientType not compatible across @redis/client versions #2556

@marwankhalili

Description

@marwankhalili

Description

Hi!

I'm trying to write a utility package for my microservices. Part of the abstraction is related to data stored in Redis‚ so I thought my utility package could reuse the microservice's client connection:

// Utility package - Installs redis as peerDependency
import type { RedisClientType } from "redis";

async function foo(redisClient: RedisClientType) {
  // Use redis client provided by the microservice
}

This utility package worked fine in one microservice, but caused a TypeScript error in another. I noticed the problem occurs when the internal @redis/client version differs between the utility package and the microservice.

Minimal reproducible example:

import type { RedisClientType as ClientA } from "@redis/client-a"; // @redis/[email protected]
import type { RedisClientType as ClientB } from "@redis/client-b"; // @redis/[email protected]

let clientA: ClientA;
let clientB: ClientB;

clientA = clientB; // TypeScript error:  Property '#private' is missing in type 'RedisClient<Record<string, never>, Record<string, never>, Record<string, never>> & WithCommands & WithModules<Record<string, never>> & WithFunctions<...> & WithScripts<...>' but required in type 'RedisClient<Record<string, never>, Record<string, never>, Record<string, never>>'.ts(2322)

package.json:

{
  "dependencies": {
    "@redis/client-a": "npm:@redis/[email protected]",
    "@redis/client-b": "npm:@redis/[email protected]",
    "typescript": "5.1.6"
  }
}

The TypeScript compatibility issue is partially due to the "private" class fields in the declaration files (see microsoft/TypeScript#18499) but also due to the unique symbol used in CommandOptions<T>. The example above only works if I remove both from the declaration files of @redis/client.

Node Redis Version

4.6.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions