-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
Experience EnhancementNoncontroversial enhancementsNoncontroversial enhancements
Description
Suggestion
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.
Examples
console.log('before') // reachable
process.exit(0) // this function returns `never` in @types/node 10.12.0
console.log('after') // should be marked as unreachableChecklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
Related issues
Metadata
Metadata
Assignees
Labels
Experience EnhancementNoncontroversial enhancementsNoncontroversial enhancements