A & B Intersection Types
Last updated: 2026-10-22
A & B Intersection Types
An intersection A & B merges several types: the value must satisfy A and B simultaneously. Great for mixin-style composition of small interfaces.
| Group | Type Composition |
|---|---|
| Kind | Type |
| Strict mode | Not required |
ℹ️ Info The editor transpiles TypeScript to JavaScript and runs it (no type checking); see each example's Output for type-check results.
📝 Syntax
type A = { id: number };
type B = { name: string };
type AB = A & B; // has both id and name
⚙️ Parameters
| A & B | & joins any number of types; more members means stricter constraints (a narrower type) |
|---|
Returns:None — intersection types are type-level only and disappear after compilation.
▶ Example
Edit the code below and click Try it to see the transpiled result:
Output:
7 login 2026-01-01T09:00:00Z
(Runtime output after transpilation; omitting timestamp from audit is a compile error — intersections require every member)
💡 Notes
ℹ️ Info Intersection is AND, union is OR: A & B demands both (narrower), A | B accepts either (wider).
⚠️ Note Intersections of primitives are never (string & number has no members); conflicting same-name properties intersect too, usually producing never.
💡 Tip Intersections shine with utility types: User & Partial<User> elegantly expresses "base plus partial override".
🏷️ Related Type Composition
💡 Related cases
More cases coming soon.
📚 Related tutorials
❓ FAQ
Q Intersection vs interface extends?
A Similar outcome, different machinery: extends inherits interface/type shapes and errors on conflicts; & composes any type expressions (including utility results) and silently resolves conflicts to never. Use extends for clearer errors.
Q What is string & number?
A never — no value is both a string and a number. Primitive intersections are almost always never, which is also useful to encode impossibility.
Q What happens when two intersected interfaces share a property name with different types?
A The property type becomes the intersection of both sides. string & number is immediately never and every assignment fails; check field types before composing with &.