namespace

Groups related declarations under a single named scope.

Since TS 1.0 Spec ↗

Syntax

namespace Name { export ... }

Examples

namespace Geometry {
  export interface Point { x: number; y: number }
  export function dist(a: Point, b: Point) {
    return Math.hypot(a.x - b.x, a.y - b.y);
  }
}

const p: Geometry.Point = { x: 0, y: 0 };
namespace App {
  export const name = 'demo';
}

Notes

Namespaces were TypeScript's pre-ES-module organization mechanism. For modern code prefer ES modules; reserve namespaces for ambient declaration files and for augmenting existing global APIs. Only `export`ed members are visible outside the namespace.

See also