Skip to content

FlashcardNot attempted

any vs unknown vs never

Recall it before you reveal

Explain any, unknown and never in one sentence each, with where each appears.

Space to reveal
Show answer & explanation
  • any: turns type checking off for that value and everything it touches. An escape hatch.
  • unknown: the safe top type. Anything can be assigned to it, but you must narrow it (typeof / instanceof / a guard) before using it. Right for JSON.parse results and catch (e).
  • never: the empty type, for values that can't exist. It's the return type of functions that always throw or never return, and what's left after an exhaustive switch.

Edge case: keyof any is string | number | symbol, but keyof unknown is never.