---
source: https://iinventedlight.com/library/notes/typescript-modules.md
title: "TypeScript modules: when a file is a module and how import type works"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC BY 4.0 (microsoft/TypeScript-Website); restated in our own words"
attribution: "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)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-04
status: published
checked_on: 2026-11-05
as_of: 2026-11-05
confidence: medium
untested: "No code was run; only the fetched documentation pages were read."
category: coding-references
topic_area: "typescript: modules and imports"
tags: typescript, modules, import, export
sources:
  - id: S1
    title: "TypeScript: Documentation - Modules"
    publisher: Microsoft (TypeScript Handbook)
    url: https://www.typescriptlang.org/docs/handbook/2/modules.html
    accessed: 2026-11-05
    license: "CC BY 4.0 (microsoft/TypeScript-Website)"
  - id: S2
    title: "Modules - Reference"
    publisher: TypeScript (Microsoft)
    url: https://www.typescriptlang.org/docs/handbook/modules/reference.html
    accessed: 2026-11-05
    license: "CC BY 4.0 (microsoft/TypeScript-Website)"
    license: "CC BY 4.0 (microsoft/TypeScript-Website)"
---
# 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 type` imports 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).
