TypeScript Basics: Types, Interfaces and Unions
Learn TypeScript Basics: Types, Interfaces and Unions (Phase 14 · TypeScript (Essential for your chosen stack), JavaScript) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
JavaScript with a type checker • TypeScript adds static types to JavaScript. The compiler ( tsc ) finds mistakes before the code runs, then removes the types, leaving plain JavaScript. • Annotate with a colon: let age: number . Most types are inferred , so annotate function parameters and public APIs and let the rest infer. • Basic types: string , number , boolean , null , undefined , arrays number[] , tuples [string, number] , and any (turns checking off: avoid), unknown (safe "anything"), never .