redis-om-node icon indicating copy to clipboard operation
redis-om-node copied to clipboard

redis client #private type error

Open ladderschool opened this issue 7 months ago • 2 comments

My installed packages:

    "redis": "4.7.0",
    "redis-om": "0.4.7",
    "@redis/client": "1.6.0",
    "@redis/graph": "1.1.1",
    "@redis/json": "1.0.7",
    "@redis/search": "1.2.0",

My code:

import { createClient } from 'redis'

export const createRedisClient = (db = 0) => {
  const client = createClient({
    url: process.env.REDIS_URL,
  })

  client.on('connect', () => {
    client.select(db)
  })

  return client
}

export const redis = createRedisClient()

// Then I use this to create a redis-om repository:
redis.connect()

export const connectionsRepository = new Repository(connectionSchema, redis)

The redis client shows a typescript error:

Argument of type 'RedisClientType<{ graph: { CONFIG_GET: typeof import("<path>/node_modules/@redis/graph/dist/commands/CONFIG_GET"); configGet: typeof import("<path>/node_modules/@redis/graph/dist/commands/CONFIG_GET"); ... 15 more ...; slowLog: typeof import("<path>...' is not assignable to parameter of type 'Client | RedisConnection'.
index.d.ts(92, 5): '#private' is declared here.

If I import the createClient from '@redis/client' I get a similar error:

Argument of type 'RedisClientType<RedisModules, RedisFunctions, RedisScripts>' is not assignable to parameter of type 'Client | RedisConnection'.
  Type 'RedisClientType<RedisModules, RedisFunctions, RedisScripts>' is not assignable to type 'RedisClientType<{ graph: { CONFIG_GET: typeof ...

Here's my tsconfig.json:

{
  "compilerOptions": {
    "noEmit": true,
    "allowJs": true,
    "esModuleInterop": true,
    "target": "esnext",
    "module": "esnext",
    "moduleResolution": "bundler",
    "allowSyntheticDefaultImports": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
   }
}

ladderschool avatar Jun 19 '25 21:06 ladderschool

I was not able to find a solution, but one workaround could be this:

export const connectionsRepository = new Repository(connectionSchema, redis as unknown as RedisConnection)

grauzonee avatar Sep 10 '25 10:09 grauzonee

@grauzonee I just posted a question about your workaround. Smh 🥲

FrancescoDiMuro avatar Sep 12 '25 22:09 FrancescoDiMuro