intersection type
A type written A & B that requires a value to satisfy both types at once, combining their properties.
In more detail
Identifiable & Timestamps & TenantScoped builds one record type from reusable pieces. If both sides give the same property incompatible types, such as string and number, that property becomes never and no value can be created.
Example
type DatabaseRecord = Identifiable & Timestamps & TenantScoped;Related terms
- union type — A type that allows one of several listed types or values, written with a vertical bar, such as int | None in Python or "small" | "large" in TypeScript.
- mixin — A reusable piece of shape or behaviour that is combined into other types, instead of inherited from a single parent class.
- never (type) — The TypeScript type with no values, used for code that can never be reached or functions that never return.
- types as sets — A way of thinking about types as sets of possible values, so unions are combined sets and intersections are overlaps.
Taught in
- Type Aliases Versus Interfaces: Declaration Merging — Production TypeScript
- Optional Properties, Readonly And Index Signatures — Production TypeScript
- Union Types, Intersections And Property Conflicts — Production TypeScript
- Typeof Guards, Truthiness And Equality Narrowing — Production TypeScript