What You'll Learn
You'll learn how to combine three or more types using the & operator, creating a new type that requires all properties and constraints from every intersected type.
The Core Idea
So far, you've seen intersections with two types: A & B creates a type that has everything from both A and B. But the & operator can chain as many types as you need.
When you write A & B & C, TypeScript creates a type that simultaneously satisfies all three types. The resulting value must have:
- Every property from
A - Every property from
B - Every property from
C
Think of it like a checklist at a security checkpoint. If three different officials each have their own requirements, you need to satisfy every single one to pass through.
Plain English Example
type HasName = { name: string };
type HasAge = { age: number };
type HasEmail = { email: string };
type User = HasName & HasAge & HasEmail;
const validUser: User = {
name: "Alice",
age: 30,
email: "alice@example.com"
};
// Error: missing 'email' property
const invalidUser: User = {
name: "Bob",
age: 25
};
The User type demands all three properties because it intersects all three types.
Chaining More Types
You can chain as many as you need:
type A = { a: string };
type B = { b: number };
type C = { c: boolean };
type D = { d: symbol };
type Everything = A & B & C & D;
// Must have a, b, c, AND d
Key Takeaway: Chain multiple types with & to create a type requiring all properties from all intersected types—A & B & C means satisfying every single one simultaneously.