What is the difference between type and interface

· Category: TypeScript

Short answer

interface declares object shapes and supports declaration merging. type creates aliases for any type, including unions and primitives, but cannot be reopened.

Key differences

  • Extensibility: Interfaces can be merged by declaring the same name multiple times. Types cannot.
  • Unions: type can represent union types (type Status = 'active' | 'inactive'), while interface cannot.
  • Implementation: Classes can implement both interface and type aliases that describe object shapes.
  • Performance: In general, interfaces produce better error messages and are slightly more performant during type checking in large projects.

When to use each

  • Use interface for public API shapes and when you expect declaration merging.
  • Use type for unions, tuples, mapped types, and complex type transformations.
  • Many teams default to interface for objects and reserve type for utility types.