allowUnreachableCode
Code after a return
Set it to `false` — the default only warns in the editor, and a warning is not a build failure.
- Since
- TypeScript 1.8
- strict
- Not in strict
- In your tsconfig
"allowUnreachableCode": false
The same snippet both times. Only the option changed.
With it off
"allowUnreachableCode": trueexport function run() { return 1 const after = 2 }
Compiles clean
With it on
"allowUnreachableCode": falseexport function run() { return 1 const after = 2 }
Emits TS7027
Why the compiler bothers
This option has three states rather than two, which is why it is easy to get wrong. Left undefined it produces an editor suggestion; set to `false` it produces an error; set to `true` it produces nothing. Unreachable code is never intentional — it is an early return added during a fix, a `throw` moved up, a branch that stopped being a branch — and the only one of the three settings that stops it reaching main is the explicit `false`.
Takeaway
Undefined is not the same as `false` here. Write the `false`.
Where to go next
22 options

