TypeScript Syntax

declare module — module augmentation

Within an external module, a declaration targeting an existing module can extend mergeable declarations. It does not add runtime behavior automatically. An augmentation cannot introduce unrelated top-level declarations or augment a default export by its default name. The fixture explicitly installs the new method. Multi-file example: save each labeled file separately in one directory and compile the project. Observed output: '12'. Local verification: TypeScript 5.8.3, strict mode, ES2022, CommonJS, Node.js 22.16.0. Disposable library declarations are enabled for the fixture suite.

Formal Syntax & Structure

typescript syntaxtypescript
declare module "./module" { interface Existing { member: T; } }

Working Example

Example Snippettypescript
// File: box.tsexport class Box { constructor(public value: number) {} }
// File: patch.tsimport { Box } from "./box";declare module "./box" { interface Box { double(): number; } }Box.prototype.double = function () { return this.value * 2; };
// File: main.tsimport { Box } from "./box";import "./patch";console.log(new Box(6).double());
TypeScript Reference