In TypeScript, never is a bottom type (that is, primitive) that you can use to indicate the type of values that never happen. This type represents the absence of type; you can see it as the exact opposite of any. When TypeScript performs code flow analysis, it identifies sections of code that are unreachable; when it discovers one, it uses the never type.
You can also use the never type yourself in the following cases:
- As the return type of a function that will never return
- As the type for variables under type guards that are never true
If you don't specify the never type yourself, TypeScript will use it when it detects a situation where something can never occur. For example, never will be inferred as the return type of the following function:
function doSomethingForever() { while(true) { console.log("Still busy..."); } ...