TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
never type represents the bottom type in TypeScript’s type system. It denotes a state that logically cannot exist, a value that will never occur, or an empty set of values. Because it is an empty set, no value can ever be assigned to a variable of type never at runtime.
Type System Mechanics and Assignability
As the bottom type,never sits at the very base of the type hierarchy. This dictates strict rules regarding assignability:
neveris assignable to every type. Because an empty set is a subset of every set, anevervalue can be safely assigned to any other type.- No type is assignable to
never. You cannot assign any value to anevertype, except anothernever. Even the top typeanycannot be assigned tonever.
Behavior in Type Operations
When evaluated within algebraic data types,never behaves according to standard set theory rules for empty sets.
In Union Types (|)
never acts as the identity element in a union. Adding an empty set to a union does not change the possible values, so the TypeScript compiler completely absorbs and removes never from the resulting type.
&)
never acts as the absorbing element in an intersection. The intersection of any set with an empty set is always an empty set. Furthermore, intersecting mutually exclusive types inherently produces an empty set, which TypeScript resolves to never.
Function Return Inference
TypeScript automatically infers thenever type as the return type for function expressions and arrow functions that possess an unreachable end point. This occurs when a function:
- Throws an exception, abruptly terminating execution.
- Contains an infinite loop, preventing it from ever returning control to the caller.
- Returns the result of another function that returns
never.
function throwError() {}, historically and currently infer void rather than never in these scenarios unless explicitly annotated).
undefined), its return type is void, not never. void means a function returns nothing of value, whereas never means the function never successfully finishes executing.
Control Flow Analysis and Exhaustiveness Checking
TypeScript’s control flow analysis usesnever to represent unreachable code paths. When evaluating a union type through conditional statements (like switch or if/else), TypeScript narrows the type based on the branches taken. If all possible constituents of the union have been exhausted by type guards, the remaining type narrows to never.
This mechanic enforces compile-time exhaustiveness checking:
Shape union is later expanded (e.g., adding { kind: "triangle" }) but the switch statement is not updated, the default branch will infer shape as the unhandled type ({ kind: "triangle" }). The assignment to exhaustiveCheck will then trigger a compile-time error because a { kind: "triangle" } is not assignable to never, ensuring the developer handles all possible cases.
Master TypeScript with Deep Grasping Methodology!Learn More





