This condition will always return 'false' since the types '"development" | "production" | "test"' and '"local"' have no overlap.ts(2367)

Viewed 708

I'm trying to do this

if (process.env.NODE_ENV === "local") {
  links = [authLink, apolloLogger, uploadLink];
}

But am getting this

(property) NodeJS.ProcessEnv.NODE_ENV: "development" | "production" | "test"
This condition will always return 'false' since the types '"development" | "production" | "test"' and '"local"' have no overlap.ts(2367)

This works fine in JS. The NODE_END is a string.

Oddly (I'm using create-react-app) if I use this, it works

REACT_APP_NODE_ENV=local
if (process.env.REACT_APP_NODE_ENV === "local") {
  links = [authLink, apolloLogger, uploadLink];
}
2 Answers

to check for the local env it should be

if (process.env.NODE_ENV === "development") {
  links = [authLink, apolloLogger, uploadLink];
}

The same is pointed out in the error that there are ENVs "development" | "production" | "test" but you are trying to compare it with value local which does not exists and hence this will always return false.

You see the error says no overlap

Related