BeCuriouzLearn something new every day
any, unknown, never & void: The Four Odd Types
💡 Reach for unknown over any to stay type-safe, and let never and void describe functions that never return or return nothing useful.
So far you've met concrete types like string and number. TypeScript also ships four special types that don't describe ordinary values — they describe how much the type-checker knows. Getting them right is what keeps your code safe.
any is the escape hatch. It means "turn off type-checking for this value." You can call anything on it, assign it anywhere, and TypeScript stays silent — including when you're wrong. It's a virus: one any can leak untyped values through your whole program. Use it as a last resort.
let x: any = "hi";
x.toFixed(2); // no error... but crashes at runtimeunknown is the safe cousin of any. Any value fits into an unknown, but you can't use it until you narrow it (recall type narrowing from earlier). This forces you to check first, so mistakes are caught.
let y: unknown = JSON.parse(input);
// y.toFixed(2); // ❌ error: must check first
if (typeof y === "number") y.toFixed(2); // ✅ safenever is the impossible type — a value that can never occur. A function that always throws or loops forever returns never. It's how TypeScript proves a branch is unreachable. void is the absence of a useful return — what functions that return nothing (like console.log) give back; the value is undefined, but you're told not to rely on it.