The TypeScript Type System
TypeScript does not change how your code runs: its whole point is a layer of types checked at compile time and erased before the JavaScript ships. Knowing that layer means being able to describe a value more precisely than "object" or "number", and letting the compiler catch whole classes of errors before runtime.
At the base sit seven primitives, and on top of them: collections (arrays and tuples), named constants (enum), and three special types — any, unknown, never — that govern how strict the checking itself is. Almost every beginner mistake here is a mix-up of these roles: number taken for int, any taken for "safe", enum taken for a "free" annotation. The full map lives in the layers below.
Topic map
- Primitive types — the seven atoms:
string,number,boolean,null,undefined,symbol,bigint; onenumberfor both ints and floats. - any, unknown, never —
anyturns off checking,unknownis the safe top type,neveris the empty type with no values. - Tuples — a fixed-length array with a type per position; how it differs from a plain array.
- Enums — named constants, numeric versus string, runtime cost, and
const enum.
Common traps
| Mistake | Consequence |
|---|---|
Looking for separate int and float | One number (an IEEE-754 double) covers both ints and floats |
Reaching for any to silence the compiler | any disables checking in both directions — safety is lost silently; prefer unknown |
Using unknown without narrowing | Member access is rejected until the value is narrowed with a type guard |
| Confusing a tuple with an array | A tuple has fixed length and a type per position; number[] does not |
Assuming a numeric enum starts at 1 | The first member is 0 by default |
Forgetting a numeric enum emits an object | A numeric enum emits a real JS object; a const enum inlines instead |
Interview relevance
Basic types come up on almost every junior/middle TypeScript interview — but the check is understanding of roles, not a list of keywords. A candidate who explains number as "a single IEEE-754 double for both ints and floats" and unknown as "the safe replacement for any that forces narrowing" immediately stands out from "well, they're types for variables".
Typical checks:
- The full primitive list and that
numberis not split intoint/float. - The difference between
any(checking off) andunknown(checking kept, narrowing required), plus the role ofnever. - How a tuple differs from an array and why a fixed shape matters.
- Numeric versus string
enum: reverse mapping, the runtime object, the cost ofconst enum.
Common wrong answer: "any and unknown are the same thing." That opens the discussion that unknown keeps you safe (it forces a type guard before use) while any fully disables checking in both directions — and why unknown is almost always preferable.