← All notes

TypeScript namespaces vs modules

Answer:

Namespace example

namespace Validation {
  export interface StringValidator { isAcceptable(s: string): boolean; }
  export const zip = /^[0-9]+$/;
}
Validation.zip.test("98052");

Only exported members are visible outside. Namespaces can span multiple files and be aliased with import v = Validation;.

Modules instead

// validation.ts
export const zip = /^[0-9]+$/;
// app.ts
import { zip } from "./validation";

Modules contain both code and declarations, get dependency tracking from bundlers and runtimes, and are the default in Node.js.

When namespaces still fit

Because the consumer of a module decides what name to assign it, there's no need to proactively wrap up the exported symbols in a namespace. (S2)

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: TypeScript (Microsoft), TypeScript: Documentation - Namespaces, CC BY 4.0 (microsoft/TypeScript-Website); TypeScript (Microsoft), TypeScript: Documentation - Namespaces and Modules, CC BY 4.0 (microsoft/TypeScript-Website).

Cite this

Permanent ID: iil:note:rzw56xea

iinventedlight. 2026. "TypeScript namespaces vs modules." iinventedlight Library, iil:note:rzw56xea, version of 2026-11-04. https://iinventedlight.com/library/notes/typescript-namespaces/. License: CC-BY-4.0.

@misc{iil_note_rzw56xea,
  author = {{iinventedlight}},
  title = {{TypeScript namespaces vs modules}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-04},
  url = {https://iinventedlight.com/library/notes/typescript-namespaces/},
  note = {Permanent ID iil:note:rzw56xea. 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-namespaces.md.