intermediate

unknown, any, and never

Separate untrusted values, escape hatches, unreachable states, exhaustive checks, and safe boundaries.

`unknown` means a value exists but must be checked before use. `any` opts out of type checking and should be isolated in small adapters. `never` represents impossible values or unreachable code paths, useful for exhaustive checks and functions that always throw.

Casting `unknown` straight to a target type without validation is `any` with extra steps. A reachable `never` branch signals a broken union model.

On interviews: explain with a concrete example and name what interviewers probe in production code.

Common pitfalls: mixing similar APIs and forgetting edge cases during live coding.

The trade-off is often clarity versus safety or expressiveness versus maintainability. Checklist:

  • Use unknown for external data.
  • Validate before access.
  • Fence any.
  • Use never for exhaustive checks.