TypeScript · Lesson 19 of 42
Intersection types: combining object types
Combine several object types into one with the & operator, see how conflicting properties behave, and compare intersections with interface extension.
UNDERSTAND IT. THEN TRY IT.
What you can do after this lesson
You will be able to build a larger type out of smaller reusable pieces. This is how real codebases avoid repeating the same fields in many places, and it is the natural companion to unions: where a union says "one of these", an intersection says "all of these".
The & operator
An intersection type is written with an ampersand and describes a value that has everything from both types:
type Named = { name: string };
type Aged = { age: number };
type Person = Named & Aged;
const person: Person = { name: "Asha", age: 30 };
console.log(person.name, person.age);Asha 30A value of type Person needs both name and age. Leave one out and the compiler complains:
type Named = { name: string };
type Aged = { age: number };
type Person = Named & Aged;
const person: Person = { name: "Asha" };example.ts(5,7): error TS2322: Type '{ name: string; }' is not assignable to type 'Person'.
Property 'age' is missing in type '{ name: string; }' but required in type 'Aged'.The message says exactly which part of the intersection is not satisfied. Be careful with the words: a union (|) accepts values that satisfy at least one member, and an intersection (&) demands values that satisfy all members.
Composing from reusable pieces
The most common use is combining small, focused types. For example, many records share an identifier and timestamps:
type WithId = { id: number };
type WithTimestamps = { createdAt: string; updatedAt: string };
type Product = { name: string; price: number };
type StoredProduct = Product & WithId & WithTimestamps;
const item: StoredProduct = {
id: 1,
name: "Pen",
price: 2.5,
createdAt: "2026-11-01",
updatedAt: "2026-11-02",
};
console.log(`${item.id}: ${item.name} (${item.updatedAt})`);1: Pen (2026-11-02)If you later add a field to WithTimestamps, every type built from it gets the field, and the compiler shows you every object that now needs updating.
Intersections of functions and primitives
You can intersect anything, but not everything is sensible. Two primitive types that share no values give never:
type Impossible = string & number;
const value: Impossible = "hello";example.ts(2,7): error TS2322: Type '"hello"' is not assignable to type 'never'.Reading it plainly: no value is both a string and a number, so nothing can be assigned. This is rarely written on purpose, but it explains a more common surprise.
When pieces disagree
If two object types give the same property different types, the intersection requires the property to satisfy both. When the types cannot overlap, the property becomes never:
type A = { id: string };
type B = { id: number };
type Both = A & B;
const value: Both = { id: 1 };example.ts(5,23): error TS2322: Type 'number' is not assignable to type 'never'.The error points at id: its type has become never, because nothing is both a string and a number, so no object can ever be created. When the types do overlap, the property takes the narrower type. For example, intersecting { size: string | number } with { size: number } leaves size as a number. If you see a baffling never, check whether two pieces define the same property differently.
Intersection or extends?
A very similar result comes from an interface that extends another, covered in the next lesson. The practical differences:
- Both combine object shapes, and for everyday use they are interchangeable.
- With
extends, a conflicting property is reported as an error at the point where you write it. With&, the conflict can silently turn intonever, which is more confusing. - Only intersections can combine things that are not plain object types, such as a union and an object.
A reasonable rule: use extends when you are building up one interface from another in a clear hierarchy, and & when you are combining type aliases or mixing several small pieces.
Intersections with unions
Intersections distribute across unions, and that is useful for adding a common property to several shapes at once:
type Circle = { kind: "circle"; radius: number };
type Square = { kind: "square"; side: number };
type Shape = Circle | Square;
type Labelled = { label: string };
type LabelledShape = Shape & Labelled;
const shape: LabelledShape = { kind: "circle", radius: 3, label: "wheel" };
console.log(shape.label, shape.kind);wheel circleEach member of the union gets the extra property.
Common mistakes
Confusing & with |. & means "and": the value needs everything. | means "or".
Intersecting incompatible properties. The result may become never. Make sure pieces agree.
Using intersections where one clear type would do. If a type is used once, just write the fields out.
Expecting intersections to merge methods smartly. Functions in an intersection combine as overloads, which is rarely what you want. Keep intersections to data shapes.
Exercise
Define Address, ContactInfo and Customer types, and build FullCustomer = Customer & Address & ContactInfo. Create a value with all the fields, then remove one and read the message. Then define type X = { id: string } & { id: number } and try to create a value, to see the never for yourself.
KNOWLEDGE CHECK
A quick check. You’ve got this.
Try each question. Every answer comes with an explanation.
Ready for the next small win?
Mark the lesson complete when you are ready.