TypeScript Advanced Declaration Authoring
UMD module and global declaration surface
A UMD declaration may describe a module export and an alternative global name for script consumers. The global namespace declaration does not implement a loader or create a runtime binding. The fixture uses moduleDetection: legacy to preserve script classification in the NodeNext project and checks script access and rejects module access by default; no UMD host is executed. Baseline: TypeScript 5.8.3, strict NodeNext consumer unless otherwise noted. Create the labeled files separately; do not paste this project into a single-file editor.
Formal Syntax & Structure
typescript syntaxtypescript
export = library; export as namespace GlobalName;Working Example
Example Snippettypescript
// File: tsconfig.json (omit this label){ "compilerOptions": { "target": "ES2022", "module": "NodeNext", "moduleResolution": "NodeNext", "strict": true, "types": [], "lib": [ "ES2022", "DOM" ], "noEmitOnError": true, "noEmit": true, "moduleDetection": "legacy" }, "files": [ "main.ts" ]}
// File: node_modules/demo/package.json (omit this label){ "name": "demo", "types": "index.d.ts"}
// File: node_modules/demo/index.d.ts (omit this label)declare function demo(n: number): number;export = demo;export as namespace Demo;
// File: main.ts (omit this label)/// <reference types="demo" />const result: number = Demo(3);
// Run: tsc -p . --pretty false// Expected: no diagnostics.