Q28. What is declaration merging?

Declaration merging allows compatible declarations with the same name—most commonly interfaces—to combine into one declaration. It is useful for library augmentation and ecosystem extension, but can be surprising if names collide. Type aliases do not support the same merging behavior.

An interface declared twice can accumulate members, whereas declaring the same type alias name twice is an error.

Note

Interview approach: define the concept, explain why it matters, then mention one trade-off or limitation.

TypeScript concept
// Illustrative TypeScript contract
type Identifier = string;
const id: Identifier = "item-1";
💡 The example demonstrates the compile-time contract discussed in this question.
Key Takeaways
  • Explain the concept in your own words.
  • Know the practical trade-off and its limits.
  • Use a small example to demonstrate the idea.
Knowledge Check

Which construct supports declaration merging in common TypeScript patterns?