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.

GroupType Composition
KindType
Strict modeNot 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".
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 &.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏