Incorrect TypeScript error in function returning never
18:11 17 Mar 2026

I don't understand why this script produces a TypeScript error:

"use strict";
const croak = (errMsg: string): never => {
    console.error('CROAK' + ': ' + errMsg)
    Deno.exit()
}

const main = (): never => {
    croak("An error occurred")
}

main()

I get the following error:

Check src/temp/temp1.ts
TS2534 [ERROR]: A function returning 'never' cannot have a reachable end point.
const main = (): never => {
                 ~~~~~
    at file:///C:/Users/johnd/util/src/temp/temp1.ts:7:18

error: Type checking failed.

Notice that the error is on the main() function, not the croak() function. In fact, I can put the croak() function in a separate module and it compiles without error.

The croak() function declares that it never returns. So, when I call the main() function, I declare that it never returns, and since it calls a function that itself never returns, there should not be a TypeScript error. At least that's the way I see it.

In other words, the main() function, in fact, does not have a reachable end point (unless I'm missing something).

FYI, I'm using deno as my runtime:

$ deno --version
deno 2.7.5 (stable, release, x86_64-pc-windows-msvc)
v8 14.6.202.9-rusty
typescript 5.9.2
typescript