I have got a problem with a typescript when creating a new Redis instance. I have created an .env.local file with the same names for redis url and token.
Following code below
import { Redis } from "@upstash/redis";
// @ts-ignore
export const db: Redis = new Redis({
url: process.env.UPSTASH_REDIS_REST_URL,
token: process.env.UPSTASH_REDIS_REST_TOKEN
})
Is giving me this typescript error:
TS2769: No overload matches this call. Overload 2 of 2, '(requesters: Requester): Redis', gave the following error. Argument of type '{ url: string | undefined; token: string | undefined; }' is not assignable to parameter of type 'Requester'. Object literal may only specify known properties, and 'url' does not exist in type 'Requester'.
I have been following the upstash/redis documentation, the code is working but the following error is kinda annoying
I have tried the Webstorm actions from preventing the ts errors but still didnt work
2
Answers
This is really weird, cause it should work
as a quick workaround, can you try:
This will automatically load the variables from your environment and bypasses the constructor
Unfortunately I can’t comment on Ugur Eren’s answer, but what you showed is exactly what
Redis.fromEnv()
does 🙂