LESSON 04 / 6·2 min readIntermediate

What are unknown, any and never?

Try code in the playground
01 Understand02 Recall03 Prepare

Understand the concept

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.

Important ideas

  • 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.

PAUSE & RECALL

Can you explain it without the notes?

What are unknown, any and never?

Use your own words. Explain an example and one limitation before checking the explanation.

Check your explanation

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.

CONNECT IT TO YOUR INTERVIEW

Turn this concept into a clear answer.

  • unknown keeps the burden of proof on the code using the value; any removes that protection.
Practice this concept
YOUR NEXT STEP

Keep connecting the ideas.

Next lesson: How do narrowing and type guards work?

Adapted from 01_JAVASCRIPT_TYPESCRIPT.md · “What are unknown, any and never?”. Examples are study fragments; framework behavior can depend on your version.