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
typeTestType='foo'|'bar';interfaceTestInterface{type : TestType;}classTest{test=(param : TestInterface) : boolean=>{switch(param.type){case'foo' : returntrue;case'bar' : returnfalse;default : throwError("Invalid type: "+param.type);// TS2339: Property 'type' does not exist on type 'never'.}}}
Expected behavior:
The code compiles with no errors.
Actual behavior:
tsc test.ts
test.ts(14,53): error TS2339: Property 'type' does not exist on type 'never'.
I understand the compiler knows that with the current code the default case can never be reached and the type property can not have any possible valid TestType value in this case but the whole point of having a default case is to limit the scope of the human error, compiling with a different TS version, compiler flags etc. It can also be considered a safe coding practice.
The workaround is easy but ugly and should not be necessary: