TypeScript Reference ยท tsconfig: Type Checking Options
TypeScript allowUnusedLabels option
Reference for allowUnusedLabels: error TS7028, the three settings, why an unused label is usually a typo for an object literal, and how labels work.
A label such as outer: only means something if a break outer or continue outer refers to it. An unused label is harmless to the runtime, but it often signals a mistake. The classic case is an arrow function that was meant to return an object but became a block with a label instead.
allowUnusedLabels has three states. Unset (the default): unused labels are shown as an editor hint only. true: they are ignored silently. false: an unused label is a compile error, TS7028. The option is not part of strict.
const make = () => { name: "Ada" }; // block with the label "name", not an object
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.
Syntax
{ "compilerOptions": { "allowUnusedLabels": false } }
| Value | Effect |
|---|---|
| not set | Unused labels are not an error; editors dim them as a suggestion. |
true |
Unused labels are ignored completely. |
false |
Unused labels are an error: TS7028: Unused label. |
Not part of strict; the default is "not set". Added in TypeScript 1.8.
Usage notes
- The arrow function trap.
() => { key: value }returnsundefined. The unused label error is the compiler's way of catching it, and a type annotation on the return would catch it too. - Labels are rare. Only
break labelandcontinue labelcan use them; there is nogotoin JavaScript. - Same-name labels may not be nested, but unrelated statements may reuse the name.
- Some frameworks use labels as syntax. Svelte's
$:reactive statements are labels (named$); in such projects the option must stay off ortruefor those files. - Runtime effect: none. The emitted JavaScript keeps the label.
- Type annotations help.
const broken = (): { name: string } => { name: "Ada" }fails for the wrong return type, which also exposes the mistake.