How TypeScript thinks · core
any vs unknown vs never
unknown is the safe 'could be anything' type you must narrow before use, any switches checking off, and never is the type with no values, used for impossible cases and exhaustiveness checks.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
anydisables type checking and spreads silently to everything it touches. Avoid it;noImplicitAny(part of strict) stops accidental any.unknownaccepts any value but you can't use it until you narrow it (typeof, instanceof, a type guard, or validation). Use it for JSON, catch variables and untrusted input.neverhas no values. A function that always throws returns never. In a switch over a union, assigning the leftover tonevermakes the compiler fail when someone adds a new case.- In
catch (e), e isunknownunder strict (useUnknownInCatchVariables), so checke instanceof Errorbefore reading e.message. voidmeans 'the return value is not used', not 'no value';undefinedis a real value.
The red pen
Common traps: mistake → fix
Mistake: "unknown is the same as any"
Fix: any lets you do anything; unknown lets you do nothing until you narrow it.
Mistake: "never is for functions that return nothing"
Fix: that is void; never means the function never returns at all.
Easy to hard
Questions interviewers ask, easy to hard
- Difference between any and unknown?
- Where do you use never in real code?
- How do you write an exhaustive switch that breaks the build when a new variant is added?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.