← All notes

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

Claims

Sources

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

Permanent ID: iil:note:0cjxv5yz

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.},
}

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-modules.md.