Skip to content
Tutorials Center
My learning

Topics

TypeScript Reference ยท Literal and Object Types

TypeScript intersection types

Reference for TypeScript intersection types: the & operator, combining object types, conflicting properties that become never, and intersection versus extends.

An intersection type combines several types into one that has all of their members. You write it with &. A value of type A & B must be assignable to A and to B at the same time. Intersections are most often used to merge object types, add a field to an existing type, or build mixins.

For object types, the result has the properties of every constituent. For primitives, intersections usually collapse to never, because no value can be both a string and a number.

TypeScript
type Named = { name: string };
type Aged = { age: number };
type Person = Named & Aged;

Try it

TypeScript Merging object types

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

TypeScript Conflicts collapse to never

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

Syntax

TypeScript
type Both = A & B & C;
type Fn = ((x: string) => void) & ((x: number) => void); // overloaded callable
Concept Description
Result members All properties and signatures from every constituent.
Same property in several members The property's type is the intersection of its types.
A & never never.
A & any any.

Edge cases: if the conflicting property is a discriminant (a literal type such as "a" and "b"), the whole intersection reduces to never. Intersecting call signatures produces an overloaded function type, with signatures in the order written.

Usage notes

  • Versus extends: an interface that extends another reports an error if a property type is incompatible; an intersection silently produces never for that property. Prefer extends when you want the compiler to complain early.
  • Optionality: a property optional in one member and required in another is required in the intersection.
  • Branding: string & { __brand: "X" } makes nominal-like types; the brand has no runtime existence.
  • Distribution: (A | B) & C is equivalent to (A & C) | (B & C).
  • Readability: hovering over a large intersection shows A & B & C; wrap it in a mapped type { [K in keyof T]: T[K] } to flatten it for display.
  • Performance: deeply nested intersections with many members are costlier to compare than a single interface.
  • Mixins: function mix<A, B>(a: A, b: B): A & B is the classic typing for Object.assign.