TypeScript tutorialLesson 14Free preview
TS Casting
This lesson is part of TypeScript · All levels
Summary
Casting or type assertion tells the compiler that you know the actual type better than the result of the inference. The syntax can be either an ace keyword or a generic form in square brackets. The assertion doesn't change the runtime value, it just affects the type check.
Key points
- The assertion does not change the value at runtime
- Syntax: x as T or <T>x
- Unknown is often used as a bridge of double assertion
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.