top type
A type that every other type fits into, so it can hold any value; in TypeScript both unknown and any play this role.
In more detail
unknown is the safe top type: it accepts everything but lets you do nothing without checking. any is an unsafe escape hatch that behaves as both top and bottom.
Related terms
- unknown (type) — The type-safe type for a value that could be anything, which you must narrow before you can use it.
- any (type) — The TypeScript type that switches off type checking for a value, so anything can be done with it without errors.
- bottom type — A type that no value belongs to, so it fits into every other type; in TypeScript this is never.
- types as sets — A way of thinking about types as sets of possible values, so unions are combined sets and intersections are overlaps.
Taught in
- any Versus unknown: Defensive Typing In Practice — Production TypeScript
- never: The Bottom Type And Exhaustive Switch Checking — Production TypeScript