So, I have a logic that sets different baseURLs depending on the NODE_ENV that I am in.
My problem is that process.env.NODE_ENV
has only two types, development
and production
and I also want to have the option for staging
.
So what I have tried to do is create a file called environment.d.ts
at the root folder of my project, and inside I did:
declare namespace NodeJS {
export interface ProcessEnv {
NODE_ENV: "development" | "production" | "staging";
}
}
However I am still getting the error when trying to use staging
:
This condition will always return 'false' since the types '"production"' and '"staging"' have no overlap.ts(2367)
export const baseURL =
process.env.NODE_ENV === "development"
? "http://localhost:3000"
: process.env.NODE_ENV === "staging"
? `https://ego-stage.herokuapp.com/`
: process.env.NODE_ENV === "production"
? "https://egolounge.com/"
: "http://localhost:3000";
The line that's giving me the error is the line where I am comparing if NODE_ENV
is equal to staging
, since staging
as a type is not present in the default interface for NODE_ENV
, so I need to extend it with my own definition, however the definition that I created does not supersede for some reason the default one, and when I push to the server, its not building.