Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

The & operator in TypeScript creates an intersection type, combining multiple types into a single type that enforces the constraints of all constituent types simultaneously. An entity of an intersection type must satisfy the structural contracts of every type included in the intersection.
type IntersectedType = TypeA & TypeB & TypeC;

Object Type Intersections

When applied to object types, the & operator creates a type that is structurally equivalent to an object containing the union of all property keys from the intersected types. TypeScript does not eagerly flatten or merge these into a new single object type signature; the internal representation remains an intersection, and properties are recursively intersected rather than merged.
type Alpha = { a: string };
type Beta = { b: number };

type Gamma = Alpha & Beta; 
// Structurally equivalent to an object with both 'a' and 'b', 
// but represented internally and in tooltips as Alpha & Beta.

Overlapping Properties

If constituent object types share a property key, the TypeScript compiler recursively intersects the types of that specific property. If the shared property contains object types, the intersection is applied to those nested objects:
type ConfigA = { settings: { theme: string } };
type ConfigB = { settings: { telemetry: boolean } };

type AppConfig = ConfigA & ConfigB;
// The 'settings' property is intersected: { theme: string } & { telemetry: boolean }
If the shared property contains mutually exclusive primitive types, the resulting property type resolves to never, as a value cannot simultaneously be multiple distinct primitives.
type EntityA = { id: string };
type EntityB = { id: number };

type IntersectedEntity = EntityA & EntityB;
// The 'id' property becomes string & number, resolving to never.
Crucially, if the shared property acts as a discriminant containing mutually exclusive literal types, the entire intersection type reduces to never, rather than just the individual property.
type DiscriminatedA = { kind: 'a', value: string };
type DiscriminatedB = { kind: 'b', count: number };

type ImpossibleIntersection = DiscriminatedA & DiscriminatedB;
// The entire type resolves to never, because the mutually exclusive 
// literal types in the 'kind' discriminant make the intersection impossible.

Primitive Intersections

Applying the & operator directly to mutually exclusive primitive types always yields the bottom type, never.
type Impossible = string & number;  // never
type AlsoImpossible = true & false; // never

Top and Bottom Types

The intersection operator has specific, defined interactions with TypeScript’s special top and bottom types:
  • any: Intersecting any type T with any yields any (T & any = any).
  • unknown: Intersecting any type T with unknown acts as an identity operation, yielding T (T & unknown = T).
  • never: Intersecting any type T with the bottom type never yields never (T & never = never).
type WithAny = string & any;         // any
type WithUnknown = string & unknown; // string
type WithNever = string & never;     // never

Function Overloading

When intersecting function signatures, the & operator creates a single function type with multiple call signatures (an overloaded function). The compiler evaluates these signatures in the order they are intersected.
type LoggerA = (msg: string) => void;
type LoggerB = (code: number) => boolean;

type CombinedLogger = LoggerA & LoggerB;
// Structurally equivalent to an overloaded function accepting either a string or a number.

Distributivity over Unions

The intersection operator distributes over the union operator (|). When an intersection is applied to a union type, TypeScript applies the intersection to each member of the union individually.
type A = { type: 'A' };
type B = { type: 'B' };
type C = { shared: boolean };

type Distributed = (A | B) & C;
// Resolves to: (A & C) | (B & C)
Master TypeScript with Deep Grasping Methodology!Learn More