import or export statement. The augmentation is then declared using the declare module syntax followed by the exact string literal of the target module’s specifier.
Syntax and Mechanics
Technical Constraints
- Module Context Requirement: If the augmenting file does not have any natural dependencies to import or export, you must force it into a module context using an empty export statement (
export {}). If omitted, TypeScript treats the file as a global script, and thedeclare moduleblock will create an ambient module declaration rather than augmenting the existing module. - Declaration Merging Rules: Augmentation relies strictly on interface and namespace merging. You can add new members to an existing
interfaceornamespace, but you cannot replace existing type signatures, and you cannot augment atypealias. - Top-Level Limitations: You cannot declare new top-level declarations in the augmentation. You can only patch existing declarations (such as adding properties to an existing exported interface). You cannot add entirely new top-level value exports (like new functions or variables) because ES module exports are immutable at runtime, making it impossible to provide an implementation for a newly injected top-level value.
- Default Exports: You cannot augment a
defaultexport directly. You must identify and augment the underlying named declaration that the module exports as default.
Global Scope Augmentation
To augment the global scope (which TypeScript treats as a special ambient module) from within a local module, thedeclare global syntax is used. This applies the exact same declaration merging principles to the global namespace.
Tired of Poor TypeScript Skills? Fix That With Deep Grasping!Learn More





