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.
stringI am being explicit about the strings that I want as values, this is irrelevant to the problem...interfacenot a class, or a function, there is no logical||operator here.process.env.NODE_ENVwhich is only"staging" | "production"and just to make my point about that even more clear, here is the default interface built into the node types: prnt.sc/4WWMhoIV4CIR if I add| "staging"here it works just fine, but thats located innode_modulesso it does not get pushed to the server, thats why I need to extend it.