TypeScript tutorialLesson 30Free preview
TS Type Inference
This lesson is part of TypeScript · All levels
Summary
Type inference works from the initial value, the return value, to the context of using an expression. TypeScript concludes that the type is as low as possible to remain accurate, but it remains on the safe type. When inference is not desirable, explicit annotation can add certainty.
Key points
- The initial value determines the type of variable
- The type is deduced from the returned value
- Contextual typing comes from the expected type
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.