Lesson 6 / 26
Type Inference
TypeScript figures out most types on its own.
TS infers for you
No annotation needed — the initial value tells TS the type, and it's remembered from then on.
let count = 5; // inferred as number
count = "five";
// Error: Type 'string' is not assignable to type 'number'.When to still annotate
Let inference handle local variables. Annotate function parameters, return types on public APIs, and empty arrays/objects — inference has nothing to go on there.