Caffeinated Coder
Book an appointment
Lesson 16 · Advanced and in practice

TypeScript in real projects

Types are checked before a program runs and then erased, so they cannot see data that arrives while it runs: a server reply, a file, a form. Follow a small program that reads {"name":"Ada","age":"36"}. Cast with as User, tsc finds nothing and it prints 361. Typed unknown and checked by a type guard, the bad reply is stopped ("bad data") and the good one prints 37.

12 min9 steps5 questionsBeginner
Fig 16 · Interactive
Loading figure…
or ← →

Quiz Unlocks after the last step.