Skip to main content
Re-exporting in TypeScript is the mechanism of forwarding exports from one module through another without binding them to the local scope. It acts as a pass-through, allowing a module to expose members defined in separate files directly to consumers. TypeScript supports several syntactical forms for re-exporting, handling named exports, default exports, and type-level constructs. Aggregate Re-export (Wildcard) Forwards all named exports from the target module. This syntax explicitly ignores the default export of the target module to prevent naming collisions.
Selective Re-export Forwards specific named exports from the target module.
Aliased Re-export Renames a specific export during the forwarding process using the as keyword.
Namespace Re-export Aggregates all exports (including the default export, if present) from the target module into a single named object.
Default Re-export Because the wildcard (*) ignores default exports, they must be forwarded explicitly. A default export can be re-exported as the current module’s default export, or aliased into a named export.
Type-Only Re-export TypeScript provides the export type modifier to guarantee that the re-exported members are strictly type-level constructs. This ensures the TypeScript compiler completely erases these statements during the JavaScript emit phase, preventing runtime reference errors.
Tired of Poor TypeScript Skills? Fix That With Deep Grasping!Learn More