any, unknown, and never
Three special types control how much TypeScript trusts a value.
any turns checking off.
unknown is the safe top type.
never means a value cannot exist.
any is an escape hatch
any disables type checking for that value.
You can read any property and pass it anywhere.
Use it only as a temporary bridge while migrating JS.
Migrating means moving old JavaScript into TypeScript.
Otherwise you lose the benefits of TypeScript.
unknown for safer incoming data
Values from JSON or user input should start as unknown.
Unknown means you do not know what is in the box yet.
Narrow with typeof or type guards before using them.
Narrow means look closer until you know which one it is.
never for impossible values
A function that always throws returns never.
So does one that loops forever.
never means this path should not give a value.
In switch statements, assigning leftovers to never proves you handled every case.
Choosing between them
Use unknown instead of any for untrusted input.
Use concrete types over both when you can.
Concrete means a clear real type like string or User.
Reach for never when modeling dead ends and exhaustiveness.
Exhaustiveness means you covered every option.
A quick mental picture
any is a box you never look inside. Dangerous.
unknown is a closed box. Open it with checks.
never is an empty box that should stay empty.
unknown forces checks. any skips them. never marks the impossible.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.