TypeScriptInterview preparation
Intermediate·Concept·2 min read

What are unknown, any and never?

Practice this question

Definition:

any allows operations without normal type checking, while unknown accepts any value but requires checks before use. never represents a situation where no value is possible, such as the result of a function that always throws. These types describe different levels of knowledge and should not be used interchangeably.

Key points:

  • unknown: check the value before using it.

  • any: skips type checks and can hide bugs.

  • never: no possible value; useful for exhaustive checks or functions that always throw.

  • Use unknown for external data until you have checked its structure.

  • Use never in exhaustive switch checks so a newly added union case causes a compile-time error.

Interview point:

  • unknown keeps the burden of proof on the code using the value; any removes that protection.
Adapted from 01_JAVASCRIPT_TYPESCRIPT.md · “What are unknown, any and never?”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.