Namespace
In one line
A namespace is a TypeScript construct (largely superseded by ES modules) that groups related declarations under a single name to avoid global scope pollution.
In simple words
Namespaces group related code under a named container. You declare them with namespace Name { ... } and access members with dot notation: Name.function().
Namespaces were the original TypeScript module system before ES modules became standard. They are now largely superseded by ES modules (import/export), but still appear in declaration files and legacy code.
For new code, prefer ES modules. Use namespaces only when working with legacy code or when you need to group types and values in a single declaration file without module boundaries.
Example
namespace Geometry {
export const PI = 3.14159;
export function area(r: number) { return PI * r * r; }
}
console.log(Geometry.area(5)); // 78.54The Geometry namespace groups PI and area. Only exported members are accessible outside.
Related terms
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.