SonarTS icon indicating copy to clipboard operation
SonarTS copied to clipboard

Rule idea: switch statement on union types should be exhaustive

Open andrea-guarino-sonarsource opened this issue 5 years ago • 0 comments

RSPEC-3562

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;
    }
}