Type Inference
ELI5 — The Vibe Check
Type inference is the compiler being smart enough to figure out what type something is without you having to spell it out. You write x = 5 and it thinks 'oh, that's obviously a number, I got it.' Less typing, same safety.
Real Talk
Type inference is a compiler feature that automatically deduces the type of an expression without explicit annotations. Languages like TypeScript, Rust, and Kotlin use it extensively so you get static type safety without the verbosity of Java-style annotations.
Show Me The Code
// TypeScript infers the type automatically
const name = "Alice"; // inferred: string
const age = 30; // inferred: number
const scores = [1, 2, 3]; // inferred: number[]
When You'll Hear This
"TypeScript's type inference caught a bug I didn't even annotate for." / "Rust's type inference is incredibly powerful."
Related Terms
Dynamic Typing
Dynamic typing is like a box that can hold anything — toys, food, or a cat — and you don't have to label what goes in it ahead of time.
Generic
A generic is like a recipe that works for any ingredient.
Interface
An interface is like a job description. It says 'whatever fills this role must be able to do X, Y, and Z' without caring how they do it.
Variable
A variable is a named box where you store information.