← All notes

Declaration merging in TypeScript

Answer: Declaration merging means the TypeScript compiler combines two or more declarations with the same name into one definition that has the features of all of them.

Interface merging

interface Box { height: number }
interface Box { width: number }
const b: Box = { height: 1, width: 2 };

Any number of declarations can merge. Non-function members of the interfaces should be unique. (S1)

Namespaces with classes, functions or enums

function greet() {}
namespace greet { export const version = 1; }
greet.version;

Module augmentation

import "express";
declare module "express" {
  interface Request { user?: { id: string } }
}

Global augmentation

declare global { interface Window { appVersion: string } }
export {};

Not mergeable

Classes cannot merge with other classes; use mixins. While it won't change any behavior at runtime, a property marked as readonly can't be written to during type-checking. (S2)

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: TypeScript (Microsoft), TypeScript: Documentation - Declaration Merging, CC BY 4.0 (microsoft/TypeScript-Website); TypeScript (Microsoft), TypeScript: Documentation - Object Types, CC BY 4.0 (microsoft/TypeScript-Website).

Cite this

Permanent ID: iil:note:er92xbyq

iinventedlight. 2026. "Declaration merging in TypeScript." iinventedlight Library, iil:note:er92xbyq, version of 2026-11-04. https://iinventedlight.com/library/notes/typescript-declaration-merging/. License: CC-BY-4.0.

@misc{iil_note_er92xbyq,
  author = {{iinventedlight}},
  title = {{Declaration merging in TypeScript}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-04},
  url = {https://iinventedlight.com/library/notes/typescript-declaration-merging/},
  note = {Permanent ID iil:note:er92xbyq. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.

For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/typescript-declaration-merging.md.