TypeScript Syntax
namespace — named declaration grouping
Namespaces group names and can emit a runtime object when they contain runtime declarations. Exported members are available outside the namespace, and compatible namespace declarations can merge. Modern modules are usually better suited for new multi-file applications. Observed output: 'items:2'. Local verification: TypeScript 5.8.3, strict mode, ES2022, CommonJS, Node.js 22.16.0. Disposable library declarations are enabled for the fixture suite.
Formal Syntax & Structure
typescript syntaxtypescript
namespace Catalog { export const item = value; }Working Example
Example Snippettypescript
namespace Catalog { export const count = 2; }namespace Catalog { export function label() { return `items:${count}`; } }console.log(Catalog.label());