Skip to content
webtype.orgwebtype.orgtsconfig

    ↑↓ move · ⏎ open · esc close

    tsconfig

    allowUnusedLabels

    A label nothing jumps to

    An unused label is usually not a label at all — it is an object literal or a type annotation that parsed as one.

    Since
    TypeScript 1.8
    strict
    Not in strict
    In your tsconfig
    "allowUnusedLabels": false

    The same snippet both times. Only the option changed.

    With it off

    "allowUnusedLabels": true
    export function run() {
      outer: for (const x of [1]) {
        return x
      }
      return 0
    }

    Compiles clean

    With it on

    "allowUnusedLabels": false
    export function run() {
      outer: for (const x of [1]) {
        return x
      }
      return 0
    }

    Emits TS7028

    Why the compiler bothers

    Labels are rare enough in modern JavaScript that an unused one is better evidence of a typo than of a loop. `{ foo: 1 }` written where a statement was expected parses as a labelled expression, not an object, and a stray `x: string` in a function body does the same — both compile silently and do nothing. Like `allowUnreachableCode`, the useful setting is the explicit `false` rather than the undefined default.

    Takeaway

    If you did not mean to write a label, this is the flag that tells you that you did.

    Where to go next

    22 options