Skip to content
webtype.orgwebtype.orgtsconfig

    ↑↓ move · ⏎ open · esc close

    tsconfig

    noUnusedLocals

    A variable nothing reads

    An unread local is usually the leftover of a change that was only half made.

    Since
    TypeScript 2.0
    strict
    Not in strict
    In your tsconfig
    "noUnusedLocals": true

    The same snippet both times. Only the option changed.

    With it off

    "noUnusedLocals": false
    export function run() {
      const unused = 1
      return 2
    }

    Compiles clean

    With it on

    "noUnusedLocals": true
    export function run() {
      const unused = 1
      return 2
    }

    Emits TS6133

    Why the compiler bothers

    The value is not in the tidiness — a bundler drops these anyway. It is that an unread variable is evidence: something was extracted and the call site was never updated, or a condition was rewritten and one branch stopped being reachable. The diagnostic is a hint rather than an error in editors, so it greys out rather than shouts, and it belongs in the build precisely because a grey line is easy to walk past.

    Takeaway

    It is a hint in the editor and an error in the build. Only one of those gets acted on.

    Where to go next

    22 options