Understanding type inference
Adding type annotations to our code means we need to write extra code which consumes our time and bloats our code. TypeScript has something called type inference which means, in many cases, it can work out a variable's type without it having a type annotation. In this lesson, we'll learn how and when we can use type inference.
We'll cover the following
Using type inference on variable declarations #
TypeScript will automatically infer the type for a variable if a type annotation hasn’t been specified.
The code below declares a variable and initializes it with the value 10
without a type annotation:
Get hands-on with 1400+ tech skills courses.