TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. It adds optional static typing, interfaces, and other features that help catch errors at compile time, improve IDE support, and make code more maintainable.
What TypeScript Is:
Key Benefits:
Catch Errors Early:
Better IDE Support:
Self-Documenting Code:
Safer Refactoring:
Modern Features:
// JavaScript - no type safety
function add(a, b) {
return a + b;
}
add(5, '3'); // Returns '53' - silent bug!
// TypeScript - catches the error
function add(a: number, b: number): number {
return a + b;
}
add(5, '3'); // Error: Argument of type 'string' is not assignable
// Type inference - TS infers types automatically
let count = 0; // inferred as number
let name = 'Alice'; // inferred as string
let items = [1, 2]; // inferred as number[]
count = 'hello'; // Error: Type 'string' is not assignable to type 'number'