Union Types in TypeScript
A union type lets a value be one of several types. Learn how to define unions, work with them safely, and avoid the most common union mistakes.
Type-safe JavaScript with TypeScript
A union type lets a value be one of several types. Learn how to define unions, work with them safely, and avoid the most common union mistakes.
An intersection type combines multiple types into one. Learn the & syntax, how it differs from extends, and when to use intersection types over interface inheritance.
A discriminated union uses a shared literal property to tell TypeScript exactly which variant of a union you are working with. Learn the pattern, exhaustiveness checking, and when to use it.
JavaScript's in operator checks if a property exists on an object. TypeScript uses it as a type guard to narrow union types by property presence. Learn how it works and when to use it.
Custom type guards let you define your own narrowing logic with the `parameterName is Type` return syntax. Learn how to write them, filter arrays, and compose guards for complex types.
Exhaustiveness checking makes the compiler catch unhandled union variants. Learn the `never`-based pattern, the `assertNever` helper, and how to guarantee every case is covered.
Use discriminated unions to model async states like loading, success, and error in TypeScript. Learn the pattern, render each state safely, and add exhaustiveness checking.
Avoid the most frequent union type mistakes in TypeScript: forgetting to narrow, misusing intersections for unions, ignoring the typeof null trap, and skipping exhaustiveness checks.
A tuple is an array with a fixed length where each position has its own type. Learn how tuples differ from arrays, when to use them, and how they catch out-of-bounds errors.
Variadic tuples let you spread an array type into a tuple, creating flexible patterns like 'a string, then any number of booleans, then a number'. Learn the ...Type[] syntax and when to use it.
Indexed access types look up the type of a specific property from another type. Learn the syntax, how to use unions and keyof as index types, and practical patterns for type-safe property access.
A tsconfig.json file tells TypeScript how to compile your project. Learn how to create one, what the key sections mean, and which options to set first.