Skip to main content
⚡ OpenDevDocs
TypeScript
programmingtypescriptGuideBeginner

Interfaces vs. Type Aliases in TypeScript

Understanding interfaces in TypeScript: declaration merging, extending interfaces (extends), implementing in classes, and choosing between interface and type.

Verified: 2026-09-30
Tested on:typescript 5.x
Platforms:
all
#typescript#interfaces#type-aliases#oop#types

Interfaces vs. Type Aliases in TypeScript

Interfaces define contractual object shapes and are the foundation of object-oriented TypeScript design.


1. Defining and Extending Interfaces

Interfaces support inheritance via the extends keyword:

interface BaseEntity {
  id: string;
  createdAt: Date;
}

interface User extends BaseEntity {
  name: string;
  email: string;
  role: "admin" | "member";
}

const adminUser: User = {
  id: "usr_10",
  name: "Alex",
  email: "alex@example.com",
  role: "admin",
  createdAt: new Date(),
};

2. Declaration Merging (Interfaces Only)

If you declare an interface multiple times with the same name, TypeScript automatically merges their declarations into a single unified interface:

// 1. Initial declaration:
interface Window {
  myAppConfig: { apiUrl: string };
}

// 2. Secondary declaration (merges with above):
interface Window {
  analyticsLoaded: boolean;
}

// window now has BOTH myAppConfig and analyticsLoaded!

3. Interfaces vs. Type Aliases: When to Use Which?

Featureinterfacetype alias
Object shapes✅ Yes✅ Yes
Primitives / Unions / Tuples❌ No✅ Yes (type ID = string | number)
Inheritanceextends InterfaceIntersection & (type C = A & B)
Declaration Merging✅ Yes (great for third-party library typing)❌ No (duplicate name throws error)
PerformanceSlightly faster compiler caching for objectsFlexible for complex mapped types

Best Practice Rule

  • Use interface for public API object contracts, library declarations, and class implementations.
  • Use type for unions, primitives, tuples, function signatures, and complex utility transformations.

On this page