TS ADVANCEDChapter 3 · TS Advanced
unknown and never
any switches type checking off. unknown is its safe twin: a value you must check before you can use it, which makes it the right type for anything from outside your program, like parsed JSON. never is the type of something that cannot happen: a function that always throws returns never, and a value narrowed until no options are left has type never.
Worked example
How it reads
- Each
typeofcheck unlocks the methods of that one type failnever returns normally, so its return type isnever- A caught error is
unknowntoo, so check or cast it before reading.message

Cloud tip: Type data at the boundary: accept
unknown, validate it once, and pass a precise type to the rest of your code.

