🧭Type Inference
Also known as Inferred Type, Type Deduction
The language works out each value's type. You do not have to write it.
Think of it like
Think of it like a box shaped for shoes. You can guess what is in it.
Example
Emma writes let count = 5 and later sets count to the word five. TypeScript stops her, though she never wrote number anywhere.
Why it matters
It keeps typed code short. You write types where they help a reader, and let the language fill in the rest.
Definition
Example code
typescript
let count = 5;
count = "five";
// Type 'string' is not assignable to type 'number'.Common mistake
Key takeaways
- 1Worked out for you. From the value you give.
- 2Still strict. Checked like a written type.
- 3Less to type. Same safety.