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

Extending Generic Interfaces

Create interface hierarchies where child interfaces extend parent generic interfaces.

Extending Generic Interfaces

What you'll learn: How to create interface hierarchies where child interfaces extend and specialize parent generic interfaces.

The Core Idea

Just like regular interfaces can extend other interfaces (which you learned in lesson 359), generic interfaces can extend other generic interfaces. This creates type-safe inheritance hierarchies where child interfaces can:

  • Pass type parameters through to the parent
  • Add new type parameters of their own
  • Add new properties or methods
  • Specialize the parent's generics with concrete types

Think of it like a family tree: the parent interface defines a general pattern with type parameters, and each child interface builds on that foundation while maintaining type safety.

Creating Interface Hierarchies

When a generic interface extends another generic interface, you must satisfy the parent's type parameters:

// Parent generic interface
interface Container<T> {
  value: T;
}

// Child extends and passes through the type parameter
interface LabeledContainer<T> extends Container<T> {
  label: string;
}

const item: LabeledContainer<number> = {
  value: 42,
  label: "Answer"
};

The child interface LabeledContainer<T> inherits the value property from Container<T> and adds its own label property. The type parameter T flows through both levels.

Adding New Type Parameters

Child interfaces can introduce their own additional type parameters:

interface Pair<T, U> extends Container<T> {
  second: U;
}

const pair: Pair<string, number> = {
  value: "first",
  second: 2
};

Here Pair extends Container by passing T to the parent, but adds a new type parameter U for its own use.

Key Takeaway: Extending generic interfaces lets you build reusable type hierarchies where child interfaces inherit parent type parameters, add new ones, or specialize them with concrete types—creating flexible, type-safe abstractions.