Why TypeScript Exists
JavaScript is dynamically typed — variables can hold any type at any time. This flexibility is powerful but leads to entire categories of runtime errors that only appear in production. TypeScript adds a static type system that catches these errors at compile time, before they ever reach users.
Basic Types
string, number, boolean, null, and undefined are the primitives. Arrays use string[] or Array<string> syntax. Object shapes are defined with interfaces or type aliases.
Interfaces vs Types
Interfaces define the shape of objects and are extendable. Type aliases can represent primitives, unions, and intersections in addition to object shapes. In practice, prefer interfaces for object definitions and type aliases for everything else.
Generics
Generics allow functions and types to work with any type while maintaining type safety. function identity<T>(value: T): T accepts any type and returns the same type. React component props, API response types, and utility functions all benefit from generics.