TypeScript Fundamentals
Any, Unknown, Never, Void
Master TypeScript's top and bottom types: any, unknown, void, and never, type narrowing strategies, exhaustiveness checking, and strict type safety.
Last Updated: July 29, 2026
•
10 min read
TypeScript provides special top and bottom types to represent dynamic values, unvalidated data, missing return values, and unreachable states.
1. any: Opting Out of Type Checking
The any type disables static type checking for a variable. You can call any method, access any property, or reassign it to any value.
Warning: Excessive use ofanydefeats the purpose of TypeScript. Preferunknownfor dynamic or unknown input.
2. unknown: The Type-Safe Top Type
unknown accepts any value (like any), but TypeScript forbids operating on an unknown value without first narrowing its type via type guards.3. void: Return Type for Functions Returning Nothing
void indicates that a function does not return a value (or explicitly returns undefined).4. never: The Bottom Type (Unreachable Code)
never represents values that never occur. It is used as the return type for functions that throw errors or enter infinite loops, or to enforce exhaustiveness checking.
Functions that Never Return
Exhaustiveness Checking in Switch Statements
5. Interactive Code Playground
Compare unknown vs any in action:
6. Common Pitfalls & Edge Cases
any Infects Downstream Code: Assigning an any value to another variable removes type safety for that variable as well.void vs undefined:void can return undefined.
- A function annotated as returning undefined MUST explicitly return undefined;.
7. Special Types Summary Table
| Type | Assignable From | Can Assign To | Primary Purpose |
|---|---|---|---|
any | Everything | Everything | Opt out of type checking (Legacy migration) |
unknown | Everything | Only unknown and any | Safe unvalidated data (APIs, JSON parsing) |
void | undefined, void | any, unknown | Function with no return value |
never | Nothing | Everything | Unreachable states & exhaustive checking |