Skip to content
webtype.orgwebtype.orgtsconfig

    ↑↓ move · ⏎ open · esc close

    tsconfig

    noFallthroughCasesInSwitch

    A forgotten break, caught

    Flags a `case` that does work and then runs into the next one, while still permitting the deliberate empty fallthrough.

    Since
    TypeScript 1.8
    strict
    Not in strict
    In your tsconfig
    "noFallthroughCasesInSwitch": true

    The same snippet both times. Only the option changed.

    With it off

    "noFallthroughCasesInSwitch": false
    export function pick(n: 1 | 2): string {
      switch (n) {
        case 1:
          const label = 'one'
        case 2:
          return 'two'
      }
    }

    Compiles clean

    With it on

    "noFallthroughCasesInSwitch": true
    export function pick(n: 1 | 2): string {
      switch (n) {
        case 1:
          const label = 'one'
        case 2:
          return 'two'
      }
    }

    Emits TS7029

    Why the compiler bothers

    Stacked empty cases are a real idiom and the check knows it: only a clause with statements in it is reported, so `case 1: case 2: return x` stays legal. That distinction is what makes the flag usable — a check that banned all fallthrough would be turned off within a week, and a check nobody runs catches nothing.

    Takeaway

    Empty fallthrough stays legal, which is the only reason this one survives in a real codebase.

    Where to go next

    22 options