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

Combining Interface and Type Alias

Intersect an interface with a type alias to merge structural definitions with computed or conditional types.

Combining Interface and Type Alias

What you'll learn: How to use intersection types to merge an interface with a type alias, combining their strengths in a single type.

Why Combine Them?

You've learned that interfaces excel at describing object shapes and can be extended or merged, while type aliases shine at creating unions, primitives, and complex computed types. Sometimes you want both in one place: the structural clarity of an interface plus the flexibility of a type alias.

Intersection types (&) let you merge these two worlds seamlessly.

The Core Pattern

When you intersect an interface with a type alias, TypeScript combines all properties from both:

interface User {
  id: number;
  name: string;
}

type Timestamps = {
  createdAt: Date;
  updatedAt: Date;
};

type UserWithTimestamps = User & Timestamps;

const user: UserWithTimestamps = {
  id: 1,
  name: "Alice",
  createdAt: new Date(),
  updatedAt: new Date()
};

The resulting UserWithTimestamps type requires all properties from both User and Timestamps.

Real-World Use Case

This pattern shines when mixing structural definitions (interfaces) with computed or utility types (type aliases):

interface Product {
  id: string;
  price: number;
}

type Auditable = {
  createdBy: string;
  modifiedBy: string;
};

type AuditedProduct = Product & Auditable;

Now AuditedProduct merges the product structure with audit metadata—keeping your code modular and reusable.

Key Takeaway: Use intersection types to combine interfaces and type aliases, merging structural object definitions with flexible computed types for maximum composability.