TypeScript — full guide
A comprehensive walkthrough of the TypeScript type system, from basic annotations to advanced utility types and patterns. Every concept you need to write type-safe JavaScript at scale.
1. Type Annotations & Primitives
TypeScript extends JavaScript by adding static types. The core primitives are string, number, boolean, null, undefined, symbol, and bigint. Annotate variables with a colon: let name: string = "Meridian". Arrays use bracket syntax: let ids: number[] = [1, 2, 3] or the generic form Array<number>. Tuple types define fixed-length arrays with known element types: let pair: [string, number] = ["violet", 0x8B5CF6]. The any type opts out of type checking entirely — use it sparingly. The unknown type is the type-safe counterpart; you must narrow it before operating on the value. Literal types let you constrain values to exact strings or numbers: type Direction = "north" | "south". Union types combine multiple possibilities: type Status = "idle" | "loading" | "error". Intersection types merge object shapes: type Admin = User & { permissions: string[] }.