never The never Type
Last updated: 2026-10-22
never The never Type
never means "no value ever": functions that throw or loop forever return it. At the type level it is a subtype of everything, most famous for exhaustive switch checks.
| Group | Basic Types |
|---|---|
| Kind | Type |
| Strict mode | Not required |
ℹ️ Info The editor transpiles TypeScript to JavaScript and runs it (no type checking); see each example's Output for type-check results.
📝 Syntax
function fail(msg: string): never {
throw new Error(msg);
}
// Exhaustiveness: the default branch turns missed cases into compile errors
type Shape = Circle | Square;
⚙️ Parameters
| (): never | Only throw, infinite loops or calls to other never functions — a normal return is an error |
|---|
Returns:never is itself the return type: the function never returns normally (throws, exits, or loops forever).
▶ Example
Edit the code below and click Try it to see the transpiled result:
Output:
caught: disk full
(Runtime output after transpilation; writing return 1 inside fail is a compile error — never functions cannot return normally)
💡 Notes
ℹ️ Info never is a subtype of every type, yet no value (not even any) is assignable to it — it is the empty set.
💡 Tip Exhaustiveness idiom: const _exhaustive: never = value in the default branch. Adding a union member without handling it fails the build right here (see exhaustive-checks).
⚠️ Note never and void both "return nothing" but differ fundamentally: void ends normally without a value; never never ends normally.
🏷️ Related Basic Types
💡 Related cases
More cases coming soon.
📚 Related tutorials
❓ FAQ
Q never vs void?
A void: the function completes normally with no value (a logger). never: the function never completes normally (throwing/looping), or no value exists at the type level.
Q What is never actually used for?
A Two main uses: annotating throwing/exiting functions, and exhaustive checks — assigning the never-narrowed union in a default branch so missed cases fail the build. Also used to filter union members in conditional types.
Q Why did my variable's type become never?
A Usually over-narrowing: after eliminating all branches nothing remains, or you touched unreachable code. Inspect what the control-flow analysis left — often a duplicated condition.