Q29. What is module augmentation?
Module augmentation extends an existing module's type declarations, often to add fields to a library interface. It must target the correct module specifier and match the library's declaration structure. Augmentation changes compile-time declarations and does not add runtime behavior by itself.
If a library adds a property at runtime through a plugin, the augmentation can tell TypeScript about it; the plugin must still actually implement it.
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
Does module augmentation itself add a runtime property?