Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Passing a strings from .env.local on new Redis instance giving an error

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

 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

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading