A namespace import is an ECMAScript module syntax feature supported by TypeScript that binds all exported members of a target module into a single, locally scoped identifier. At runtime, this identifier acts as a module namespace exotic object encapsulating all named and default exports as read-only properties. During compilation, TypeScript extends this behavior by allowing the same identifier to act as a namespace for accessing exported types, which are subsequently erased during the emit phase.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.
Mechanics and Behavior
Module Resolution and Binding The* wildcard instructs the compiler to resolve the entire export graph of the target module. The compiler constructs a single identifier (AliasName) where each exported runtime member becomes a property on the module namespace exotic object.
Default Export Handling
If the target module contains a default export, the namespace import does not bind it to the root alias. Instead, it is explicitly attached to a property named default.
Immutability
The generated runtime namespace object is strictly read-only. TypeScript enforces this at compile time. Attempting to reassign a property on the namespace object throws TS2540: Cannot assign to 'Property' because it is a read-only property. Furthermore, attempting to reassign the namespace alias itself throws TS2628: Cannot assign to 'AliasName' because it is an import.
TypeScript Type Integration
While the runtime module namespace exotic object strictly contains values (functions, objects, primitives), TypeScript allows the namespace alias to be used in type positions to access compile-time constructs (interfaces, type aliases). The compiler resolves these type accesses during static analysis and completely erases them from the emitted JavaScript.Type-Only Namespace Imports
TypeScript 3.8 introduced the ability to prefix a namespace import with thetype modifier. This guarantees that the namespace object is completely erased during the emit phase and only exists in the TypeScript AST for type checking.
Master TypeScript with Deep Grasping Methodology!Learn More





