Type Safety
ELI5 - The Vibe Check
Type safety is your programming language refusing to let you accidentally add a number to a string and get a nonsense result back, or call a function with completely the wrong shape of data, without at least warning you first. A type-safe language catches an entire category of dumb mistakes before your code ever runs, instead of letting you discover them from a confused user's bug report.
Real Talk
Type safety is the degree to which a programming language prevents type errors, meaning operations performed on values of an inappropriate or unexpected type, either at compile time (static type safety, as in TypeScript or Rust) or at runtime (dynamic type safety, as in Python raising a TypeError rather than silently corrupting data). A fully type-safe language guarantees that no operation is ever applied to data it wasn't designed to handle, catching a large class of bugs before they reach production.
Show Me The Code
// unsafe: silently returns a nonsense string
function add(a, b) { return a + b }
add("5", 3) // "53", not what you wanted
// type-safe: caught at compile time
function add(a: number, b: number): number { return a + b }
add("5", 3) // Error: Argument of type 'string' is not assignable to type 'number'
When You'll Hear This
"Switching to TypeScript gave us type safety we didn't know we were missing." / "That bug wouldn't have shipped if the API response had any type safety at all."
Related Terms
Duck Typing
Duck typing is the ultimate 'don't ask for a resume' approach. If it walks like a duck and quacks like a duck, it's a duck.
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.
Static Typing
Static typing means you have to tell the computer what type each variable is when you write the code, and it checks everything is correct BEFORE running.
Type Inference
Type inference is the compiler being smart enough to figure out what type something is without you having to spell it out.
TypeScript
TypeScript is JavaScript with a strict parent watching over it.