TypeScript modules
Short answer
Any file with a top-level import or export is a module and has its own scope. A file without them is a script whose declarations live in the global scope. [S1]
Points
- Modules do not put their exports in the global scope. [S1]
import typeimports only types. [S1]- TypeScript-specific forms (aliases, interfaces, enums, namespaces) can be imported and exported. [S2]
Claims
- id: C1 claim: A top-level import or export makes a file a module. source: S1 evidence: "any file containing a top-level import or export is considered a module"
- id: C2 claim: Modules run in their own scope, not the global scope. source: S1 evidence: "Modules are executed within their own scope, not in the global scope"
- id: C3 claim: Files without import/export are scripts in the global scope. source: S1 evidence: "is treated as a script whose contents are available in the global scope"
- id: C4 claim: TypeScript-specific declarations can be imported and exported. source: S2 evidence: "Importing and exporting TypeScript-specific declarations"
Sources
- [S1] TypeScript: Documentation - Modules. Microsoft (TypeScript Handbook). https://www.typescriptlang.org/docs/handbook/2/modules.html . License: CC BY 4.0 (microsoft/TypeScript-Website). Accessed 2026-11-05.
- [S2] Modules - Reference. TypeScript (Microsoft). https://www.typescriptlang.org/docs/handbook/modules/reference.html . License: CC BY 4.0 (microsoft/TypeScript-Website). Accessed 2026-11-05.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
Source notice: TypeScript Handbook / Website docs © Microsoft. Licensed under Creative Commons Attribution 4.0 International (https://github.com/microsoft/TypeScript-Website/blob/v2/LICENSE).
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Microsoft (TypeScript Handbook), TypeScript: Documentation - Modules, CC BY 4.0 (microsoft/TypeScript-Website); TypeScript (Microsoft), Modules - Reference, CC BY 4.0 (microsoft/TypeScript-Website).
Cite this
iinventedlight. 2026. "TypeScript modules: when a file is a module and how import type works." iinventedlight Library, iil:note:0cjxv5yz, version of 2026-11-04. https://iinventedlight.com/library/notes/typescript-modules/. License: CC-BY-4.0.
@misc{iil_note_0cjxv5yz,
author = {{iinventedlight}},
title = {{TypeScript modules: when a file is a module and how import type works}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-04},
url = {https://iinventedlight.com/library/notes/typescript-modules/},
note = {Permanent ID iil:note:0cjxv5yz. License: CC-BY-4.0.},
}
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-modules.md.