What is an Intersection Type?
You'll learn how to create types that require all properties from multiple types combined into one.
The Core Idea
An intersection type lets you merge two or more types together using the & operator. The resulting type includes every property from each component type. Think of it like a Venn diagram where you're taking the overlap plus everything else — the combined set of requirements.
If unions are "or" (a value can be this type or that type), intersections are "and" (a value must satisfy this type and that type).
How It Works
You create an intersection type with &:
type TypeA = { name: string };
type TypeB = { age: number };
type Combined = TypeA & TypeB;
const person: Combined = {
name: "Alice",
age: 30
};
The Combined type requires both name and age. You can't omit either property.
Why This Matters
Intersection types are perfect when you want to compose behavior:
type HasId = { id: number };
type HasTimestamp = { createdAt: Date };
type Entity = HasId & HasTimestamp;
const record: Entity = {
id: 1,
createdAt: new Date()
};
This lets you build complex types from smaller, reusable pieces.
Key Takeaway: Intersection types combine multiple types with &, creating a new type that demands all properties from each component type — perfect for composing features together.