According to the TypeScript handbook:
The
nevertype represents the type of values that never occur. For instance,neveris the return type for a function expression or an arrow function expression _that always throws an exception or one that never returns;_ Variables also acquire the typeneverwhen narrowed by any type guards that can never be true.
Which means that function or expression that "returns" never either terminates the program prematurely or never return (i.e. infinite loop), this leads to the section of code below it never get to execute.
console.log('before') // reachable
process.exit(0) // this function returns `never` in @types/node 10.12.0
console.log('after') // should be marked as unreachable
My suggestion meets these guidelines:
Limited by the same issue here: #8655
Specifically, see this comment here.
Reachability in your example is determined by type, but the graph is built syntactically.
I have a lint rule that forces you to write return process.exit(0) instead, which is then picked up by control flow analysis and subsequent statements are marked as unreachable: https://github.com/fimbullinter/wotan/blob/master/packages/mimir/docs/return-never-call.md
The CLI documentation contains a quick start guide: https://github.com/fimbullinter/wotan/blob/master/packages/wotan/README.md
This seems to be implemented, so the Design Limitation tag can be removed @weswigham.
Added in 3.7.
Most helpful comment
I have a lint rule that forces you to write
return process.exit(0)instead, which is then picked up by control flow analysis and subsequent statements are marked as unreachable: https://github.com/fimbullinter/wotan/blob/master/packages/mimir/docs/return-never-call.mdThe CLI documentation contains a quick start guide: https://github.com/fimbullinter/wotan/blob/master/packages/wotan/README.md