Closed ryanrhee closed 2 years ago
As a workaround:
const foo: string | undefined = "foo"
function showHelp(): never {
cli.showHelp()
throw new Error("This is unreachable code")
}
if (foo === undefined) {
showHelp()
}
// type of foo is now `string`
Since
showHelp()
calls intoprocess.exit()
, they should use the same return type.The return type of
process.exit()
isnever
, notvoid
. This tells the typescript compiler that code branches that haveshowHelp()
terminate, and that any code written as executing aftershowHelp()
should be considered dead code (similar to code after areturn
statement).