skip to Main Content

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


  1. This is really weird, cause it should work

    as a quick workaround, can you try:

    export const db = Redis.fromEnv()
    

    This will automatically load the variables from your environment and bypasses the constructor

    Login or Signup to reply.
  2. Unfortunately I can’t comment on Ugur Eren’s answer, but what you showed is exactly what Redis.fromEnv() does 🙂

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search