Course contentsShow
← TypeScript
Lesson 560 of 1,79613. GenericsFree lesson

Generic Interface Merging

Combine multiple declarations of the same generic interface using declaration merging rules.

Generic Interface Merging

What you'll learn: How to combine multiple declarations of the same generic interface to incrementally build up its shape.

The Core Idea

Just like regular interfaces can merge through declaration merging, generic interfaces can also merge — but with one critical rule: all declarations must have the exact same type parameters. When TypeScript sees multiple declarations of the same generic interface name, it combines their properties into a single unified type.

This lets you split a complex generic interface across multiple declarations, which is particularly useful when augmenting third-party generic types or organizing large type definitions.

How It Works

When you declare the same generic interface multiple times:

interface Box<T> {
  value: T;
}

interface Box<T> {
  label: string;
}

// TypeScript merges these into:
// interface Box<T> {
//   value: T;
//   label: string;
// }

const myBox: Box<number> = {
  value: 42,
  label: "Answer"
};

The type parameter T must match across all declarations. The properties from both declarations combine into one interface.

The Type Parameter Constraint

You cannot merge if type parameters differ in name, count, or constraints:

interface Container<T> {
  item: T;
}

// ERROR: Cannot merge - different type parameter name
// interface Container<U> {
//   count: number;
// }

All merged declarations must use identical type parameter signatures.

Key Takeaway: Generic interfaces merge just like regular interfaces, but every declaration must use the exact same type parameter list — TypeScript combines the properties while preserving the generic behavior.