CPCODELAB
TypeScript

Interface vs Type Alias

7 min read

Interface vs Type Alias

Both interface and type can describe object shapes, and for most use-cases they are interchangeable. The choice often comes down to team convention, but there are real differences.

  • interface supports declaration merging; type does not
  • type can alias unions, intersections, tuples, and primitives; interface cannot
  • interface extends with the extends keyword; type composes with &
  • Error messages for interface violations are sometimes clearer
  • Both compile away to zero runtime cost
ts
// Only possible with type:
type StringOrNumber = string | number;
type Pair = [string, number];

// Only possible with interface:
interface Logger {
  log(msg: string): void;
}
interface Logger {
  warn(msg: string): void; // merged!
}

// Composition comparison:
interface A { a: number; }
interface B extends A { b: string; }

type C = { a: number };
type D = C & { b: string };

A common convention: use interface for public APIs and class contracts; use type for unions, utility compositions, and local helper types. Pick one and stay consistent within a codebase.

Ready to test yourself?
Practice TypeScript— quiz & coding exercises