Intersection Types
Tasks, projects and comments all need the same two timestamps: createdAt and updatedAt. Copying those lines into every type is tedious and easy to get wrong. An intersection lets you write them once and bolt them onto anything.
The rule
A & B means both at once: every property of each.
An intersection type joins types with &. A value must satisfy all of them together:
type Task = { id: number; title: string };
type Timestamps = { createdAt: string; updatedAt: string };
type StoredTask = Task & Timestamps;
const t: StoredTask = {
id: 1,
title: "Buy milk",
createdAt: "2026-09-01",
updatedAt: "2026-09-02",
};StoredTask has all four properties. Leave any one out and it is an error, because the value would no longer be both a Task and a Timestamps.
Compare with a union. The names feel backwards at first:
- Union
A | B— the value is one or the other, so you can safely use fewer properties (only the shared ones). - Intersection
A & B— the value is one and the other, so it has more properties (all of them).
What if both sides define the same property? Its types are intersected too:
type A = { id: number };
type B = { id: string };
type C = A & B; // id: number & string, which is neverNo value is both a number and a string, so number & string is never, and no object can satisfy C. When you see never appear unexpectedly, look for a clash like this.
Intersections work with any types, not only objects, and they compose: Task & Timestamps & { ownerId: number } is perfectly normal. Interfaces offer a similar tool with extends, which you will meet in the last section.
The shortcut
Read & as "plus" for object types: Task & Timestamps is "a Task plus timestamps". Then check for clashes: "Does any property name appear on both sides with different types?"
Start with the pieces
Task,Timestamps, and a new{ ownerIds: number[] }.
Drills
Answer fast — trust the rule.
How many properties must a value of { a: number } & { b: string } have?
What is string & number?
type StoredTask = Task & Timestamps. Where can a StoredTask be used?
Which description matches a union rather than an intersection?
Remember
- A & B means both at once: every property of each.
- Read
&as "plus", then check for property names that clash. - Trap: the same property with different types on each side becomes
never.
