Why declaration merging
JavaScript lets you attach properties to almost anything; TypeScript mirrors that with merging:
interface Options { timeout: number; }
interface Options { retries: number; } // { timeout; retries }
Multiple authors can contribute to the same contract. Libraries use it to let you extend config or event shapes without forking the source.
Module augmentation
Add fields to a library's exports without rewriting it:
declare module "express" {
interface Request {
user?: { id: string };
}
}
This augments the express module, so req.user becomes known to the whole project. It is the standard way to plug custom middleware types into third-party libraries.