TypeScript · Junior · Question 58 of 75
Why can't you check if (data is User) at runtime?
- ✓Correct answer: Types are erased during compilation; to check external data at runtime you need code (a type guard or a schema like Zod)
- 2Because
isis reserved for classes - 3You can - TypeScript adds runtime checks automatically
Explanation
TypeScript only checks code at compile time. Data from APIs, localStorage or forms must be validated by real code.