> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# TypeScript Namespace Export

The `export as namespace` syntax in TypeScript is a module-level declaration that exposes a module's exports to the global scope under a single specified identifier. It provides ambient type information for Universal Module Definition (UMD) libraries, allowing the TypeScript compiler to recognize the module's members as global variables when a module loader is not present.

**Syntax**

```typescript theme={"dark"}
export as namespace Identifier;
```

**Mechanics and Compiler Behavior**

* **Type-Level Binding:** The declaration does not emit runtime JavaScript to attach the module to the global object (e.g., `window` or `global`). It strictly informs the TypeScript type checker that the underlying UMD bundle will handle the global assignment at runtime.
* **Module Requirement:** It can only be declared inside a file that is already recognized as a module by the compiler (i.e., a file containing at least one top-level `import` or `export` statement).
* **Single Declaration Limit:** TypeScript strictly allows only one `export as namespace` declaration per file. Attempting to declare multiple namespace aliases within the same module will result in a compiler error.
* **Global Access Resolution:** By default, the declared global namespace identifier is only accessible in script files. If the consuming file is a module (meaning it contains top-level `import` or `export` statements), TypeScript intentionally hides the global alias and throws an error (TS2686), enforcing explicit imports. However, this strict isolation can be bypassed by enabling the `allowUmdGlobalAccess` compiler option (introduced in TypeScript 3.5), which explicitly permits module files to access UMD globals without requiring an `import` statement.

**Implementation Example**

```typescript theme={"dark"}
// geometry.d.ts

// 1. Standard ES Module exports
export interface Vector2D {
    x: number;
    y: number;
}
export function calculateDistance(a: Vector2D, b: Vector2D): number;

// 2. Namespace export declaration (Strictly one per file)
export as namespace GeometryLib;
```

When the above declaration is included in a TypeScript compilation context, the compiler's resolution behavior depends on the nature of the consuming file and the `tsconfig.json` configuration:

**1. Consumption in a Script File**

```typescript theme={"dark"}
// script-consumer.ts (Environment without a module loader)
// No top-level imports or exports exist in this file.

// The compiler resolves 'GeometryLib' globally.
const pointA: GeometryLib.Vector2D = { x: 0, y: 0 };
const pointB: GeometryLib.Vector2D = { x: 10, y: 10 };

const distance = GeometryLib.calculateDistance(pointA, pointB);
```

**2. Consumption in a Module File**

```typescript theme={"dark"}
// module-consumer.ts (Environment with a module loader)
export const origin = { x: 0, y: 0 }; // Top-level export makes this file a module

// Default Behavior (allowUmdGlobalAccess: false):
// ERROR TS2686: 'GeometryLib' refers to a UMD global, but the current file is a module.
// Consider adding an import instead.
const distance = GeometryLib.calculateDistance(origin, { x: 5, y: 5 });

// Correct approach in a module (when allowUmdGlobalAccess is false):
// import * as GeometryLib from './geometry';

// Note: If "allowUmdGlobalAccess": true is set in tsconfig.json, 
// the direct usage of GeometryLib.calculateDistance above will compile successfully.
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor TypeScript Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
