Modules & Namespaces
Namespaces (Legacy & When to Use)
Understand legacy TypeScript namespaces versus modern ES modules.
Last Updated: July 29, 2026
•
10 min read
Namespaces were TypeScript's internal module system prior to standard ES module standardization.
1. Introduction & Architecture
2. Deep Dive & Core Concepts
In modern codebases, preferred design favours ES modules over namespaces. Namespaces are primarily used for declaring complex .d.ts structures.
3. Basic Code Example
4. Advanced Production Patterns
5. Interactive Code Playground
namespace Utility { export const version = "1.0"; }
console.log(Utility.version);
6. Common Pitfalls & Edge Cases
Warning: Do NOT use namespaces in new application code. Use standard ES modules (
import / export) instead.7. Interview Q&A & Quizzes
Q: Are Namespaces obsolete in TypeScript?
A: For application logic, yes—ES modules are standard. Namespaces are still used internally in ambient .d.ts files.
8. Summary Comparison Table
| Feature | Namespaces | ES Modules |
|---|---|---|
| Standard | Legacy TS Custom | Official ECMAScript Standard |