Assigning to never
What You'll Learn
You'll learn that never is the most restrictive type in TypeScript — nothing can be assigned to it except never itself.
Understanding never's Strict Assignment Rules
Think of never as a locked vault that accepts no deposits. Unlike unknown which accepts everything, or any which bypasses checks, never enforces an absolute guarantee: only never can be assigned to never.
This makes sense when you remember what never represents: values that cannot exist. If you could assign a string, number, or object to never, you'd be saying "this thing both exists and cannot exist" — a logical impossibility.
Assignment Attempts
let impossibleValue: never;
// ❌ Error: Type 'string' is not assignable to type 'never'
impossibleValue = "hello";
// ❌ Error: Type 'number' is not assignable to type 'never'
impossibleValue = 42;
// ❌ Error: Type 'null' is not assignable to type 'never'
impossibleValue = null;
// ❌ Error: Type 'undefined' is not assignable to type 'never'
impossibleValue = undefined;
The Only Valid Assignment
function throwError(): never {
throw new Error("This never returns");
}
let impossibleValue: never;
// ✅ This works: never can be assigned to never
impossibleValue = throwError();
This strict rule is what makes never so powerful for exhaustiveness checking and representing impossible states. TypeScript uses it to guarantee that certain code paths truly cannot happen.
Key Takeaway: never accepts no assignments except never itself, making it TypeScript's ultimate type-safety enforcement mechanism for impossible values.