Course contentsShow
← TypeScript
Lesson 434 of 1,79610. Intersection TypesFree lesson

Intersections with Primitives

Intersecting primitive types like string & number results in never since no value can be both simultaneously.

Intersections with Primitives

You'll learn how intersecting primitive types creates an impossible type that TypeScript represents with never.

What Happens When Primitives Intersect

When you create an intersection type with two different primitive types, you're asking TypeScript for a value that satisfies both types simultaneously. Think of it like asking for someone who is both "exactly 5 feet tall" AND "exactly 6 feet tall" — it's logically impossible.

type Impossible = string & number;

This type says: "I need something that is both a string AND a number at the same time." Since no value in JavaScript can be both a string and a number simultaneously, TypeScript resolves this to the never type — the type for values that cannot exist.

Why This Matters

The never type represents impossibility. If you try to assign any value to a variable of this type, TypeScript will reject it:

type StringAndNumber = string & number;

// Error: Type 'string' is not assignable to type 'never'
const value1: StringAndNumber = "hello";

// Error: Type 'number' is not assignable to type 'never'
const value2: StringAndNumber = 42;

This same principle applies to any distinct primitive types:

type BoolAndString = boolean & string;  // never
type NumAndBool = number & boolean;     // never

Key Takeaway: Intersecting different primitive types always results in never because no value can simultaneously be two different primitive types — intersections require all conditions to be met, which is impossible for distinct primitives.