• Error
  • Reported by the type checker

TS2534

A function returning 'never' cannot have a reachable end point.

A function declared to return never can finish normally. Make every path throw or loop forever, or change the return type.

What it means

never as a return type means the function never returns: every path must throw, call another never function or loop forever. If execution can reach the end of the body, the declaration is wrong.

Example

index.ts
export function fail(message: string): never {
  console.error(message);
}
ts-r-check -p tsconfig.json --pretty false ts-r output
index.ts(1,40): error TS2534: A function returning 'never' cannot have a reachable end point.

Recorded by node scripts/verify-examples.mjs with ts-r built from commit 6deaf01. The example uses the default tsconfig: strict, target: es2022, module: esnext, moduleResolution: bundler.

How to fix

  • Throw at the end: throw new Error(message).
  • Change the return type to void if the function is allowed to return.