any— disables checking; escape hatch only.unknown— safe top type; narrow before use.never— no values; used for impossible branches and throwing functions.
Choosing between them
Use unknown for JSON.parse results and external APIs—force narrowing before use. Reserve any for incremental migrations with a TODO. Use never for functions that always throw or infinite loops.
Interview angle
Teams prefer: “We accept unknown at boundaries and narrow; we avoid any in new code.”
Self-check
- Why is
unknownsafer thananyin a library wrapper?
Pitfall: Prefer unknown at boundaries; avoid new any in application code.
Interview prep
- unknown vs any?
unknownforces narrowing before use;anydisables checking. Preferunknownat boundaries.