SonarTS
SonarTS copied to clipboard
Rule idea: switch statement on union types should be exhaustive
The new proposed rule should always check for exhaustiveness wherever there is a switch on a union type.
type Shape = Square | Rectangle | Circle | Triangle;
function foo(s: Shape) {
switch (s.kind) { // Noncompliant: switch statements should be exhaustive on union types
case "square":
f();
break;
case "rectangle":
g();
break;
case "circle":
h();
break;
}
}