Q6: What is the difference between `type` aliases and `interface` declarations?

Difficulty:EasyTopic:Core Concepts

Both type and interface define structural contracts, but they differ in capabilities:

Interface vs Type Alias Comparison

Declaration Merging

Supported by interface | Unsupported by type

Multiple interface declarations with the same name automatically merge properties.

Union & Primitives

Unsupported by interface | Supported by type

Type aliases can define unions (A | B), primitives, tuples, and mapped types directly.

Extensibility

extends keyword vs Intersection (&)

Interfaces extend other interfaces; types create intersections.

Key Takeaways
  • Use interface for public API contracts and object structures that benefit from declaration merging.

  • Use type for union types, tuples, primitives, and complex mapped/conditional types.