Want a faster signal before interviews? Take the Interview Ready Check →

DAY 2 OF 30

Type inference

Yesterday, in one sentence

What are the 7 primitive types in TypeScript?

Interview question

What is a type annotation, and what happens to them at build time?

Type inference is TypeScript working out a type from the value you assign, without you writing a type annotationType Annotation.

let title = "Day 2"; // inferred as string
let count = 30; // inferred as number

count = 31; // ok
count = "thirty"; // ❌ Type 'string' is not assignable to type 'number'

Inference is the default, and most TypeScript you write has no annotations in it at all. The value tells the compiler everything it needs.

Check yourself

What type does TypeScript infer for count here?
let count = 30
What is type inference in TypeScript?