> ## 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.

# TypeScript Bitwise AND

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.

```typescript theme={"dark"}
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.

```typescript theme={"dark"}
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:

```typescript theme={"dark"}
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.

```typescript theme={"dark"}
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.

```typescript theme={"dark"}
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`.

```typescript theme={"dark"}
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`).

```typescript theme={"dark"}
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.

```typescript theme={"dark"}
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.

```typescript theme={"dark"}
type A = { type: 'A' };
type B = { type: 'B' };
type C = { shared: boolean };

type Distributed = (A | B) & C;
// Resolves to: (A & C) | (B & C)
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor TypeScript Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
