-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Create Redis client in TypeScript. Reis 4.0.0. #1748
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Ahoy! I'd also like inputs on this. What is the type of the object returned by |
It's import { RedisClientType } from '@node-redis/client/dist/lib/client'; but this has two cons:
Together, these two things mean my code is likely to break when these packages change. |
#1732 has more on this |
thank you @jamesarosen.
So, I still don't know, how to use RedisClientType - how to specify a variable type or return type of a function. |
This worked for me: import { createClient } from 'redis'
export type RedisClientType = ReturnType<typeof createClient>
export default async function start(): Promise<RedisClientType> {
const redis: RedisClientType = createClient({ url: … })
await redis.connect()
return redis
} |
Define and export own redis client type worked for me!
The second option to get the redis client type as ReturnType doesn't work for function return types:
Working example:
|
Duplicate of #1673 |
Guys, if you take on the approach suggested by our fellow @jamesarosen you are probably going to hit some performance issues when compiling your typescript project. I removed this explicit workaroundy type definition and it decreased my build time from 5+ minutes to 5 seconds. That's what I experienced |
Hi all,
I am relative new to TypeScritp. That's why my question is eventually really obvious. I need help with creating a redis client in TypeScript. Especially declaring a client type:
With this code I receive a TypeScript error "type RedisClientType<...> is not assignable to never".
What is the right approach to instantiate redis client?
Perhaps you could just provide an TypeScript example.
Thank you in advance
The text was updated successfully, but these errors were encountered: