Type safety means:
your code is prevented from using values in ways that don’t match what they actually are.
In simpler terms, the language and compiler help stop you from doing “wrong things with data” before the code ever runs.
function double(x) {
return x * 2;
}
double("hello"); // no error, returns NaN
The bug shows up at runtime, possibly in production.
function double(x: number): number {
return x * 2;
}
double("hello"); // compile-time error
The compiler stops you before the app even runs.
Type safety ensures:
null / undefined