You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
interfaceProcessEnv{NODE_ENV: 'development'|'production';}declareconstenv: ProcessEnv;declarefunctiongetEnvironmentVariable<KextendskeyofProcessEnv>(key: K): ProcessEnv[K];constgetNodeEnvironment=()=>{// 💣 Not all code paths return a value.ts(7030)switch(getEnvironmentVariable('NODE_ENV')){case'development':
return'development';case'production':
return'production';}};
Expected behavior:
No error. The expression provided to switch evaluates to either 'development' or 'production', so the switch statement is exhaustive.
Interestingly enough, if we assign the expression to a local variable, the function becomes exhaustive.
constgetNodeEnvironment=()=>{// ✅ No errorconstenvironment=getEnvironmentVariable('NODE_ENV');switch(environment){case'development':
return'development';case'production':
return'production';}};
TypeScript Version: 3.7.1.-rc
Search Terms: noFallthroughCasesInSwitch, exhaustive, exhaustiveness, switch
Code
Expected behavior:
No error. The expression provided to
switch
evaluates to either'development'
or'production'
, so the switch statement is exhaustive.Interestingly enough, if we assign the expression to a local variable, the function becomes exhaustive.
Actual behavior:
A compile-time error for
getNodeEnvironment
.Playground Link
The text was updated successfully, but these errors were encountered: