- Error
- Reported by the binder
TS7027
Unreachable code detected.
Code after a `return`, `throw`, `break` or `continue` can never run. Remove it or fix the control flow above it.
What it means
The binder found statements that can't be reached because the code before them always exits. It is reported when allowUnreachableCode is false; with the option unset, editors show the code faded instead of reporting an error.
Example
{
"compilerOptions": {
"strict": true,
"target": "es2022",
"module": "esnext",
"moduleResolution": "bundler",
"noEmit": true,
"allowUnreachableCode": false
}
}
export function f(): number {
return 1;
console.log("done");
}
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.ts(3,3): error TS7027: Unreachable code detected.
Recorded by node scripts/verify-examples.mjs with ts-r built from commit 6deaf01.
How to fix
- Delete the unreachable statements, or move them before the
return. - If the early exit is a mistake (for example a stray
return), fix that instead.