Declaration Merging & Module Augmentation
How TypeScript merges interfaces, augments modules (like Express/NextAuth), and why this matters in real codebases.
F
Frontend Interview Team
February 08, 2026
30‑second interview answer
TypeScript can merge interface declarations with the same name—useful for extending existing types. Module augmentation lets you add types to third-party modules (e.g., adding fields to Express.Request). This is a safe way to extend library types without forking them.
Interface merging
interface Config {
timeout: number;
}
interface Config {
baseUrl: string;
}
// Config becomes { timeout: number; baseUrl: string }Types (type) do not merge.
Module augmentation (common in backend + auth)
Example: extend Express request:
// types/express.d.ts
import 'express-serve-static-core';
declare module 'express-serve-static-core' {
interface Request {
userId?: string;
}
}Now req.userId is typed.
When to use it
- adding custom fields provided by middleware
- augmenting global types (rare, do carefully)
Pitfalls
- augmentations must be included by TS (tsconfig include)
- name collisions if you over-augment
Mini Q&A
Q1: Why can interfaces merge but types can’t?
- Language design: interfaces are open/extendable.
Q2: What is module augmentation?
- Extending types for an imported module.
Q3: Is it runtime behavior?
- No, types only.
Summary checklist
- I can show interface merging.
- I can augment a module safely.
- I understand it’s compile-time only.