TypeScript’s export assignment (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.
export =) is a module syntax designed to model the CommonJS module.exports and AMD return patterns. It specifies a single entity or expression as the exact exported value of a module, replacing the module object entirely.
Unlike standard ECMAScript modules (ESM) where export default creates a specific default export binding, the export = syntax binds the exported value directly to the module root.
Syntax
The export assignment is declared using theexport = keywords followed by any valid expression. This can be an identifier, an inline object, an anonymous class, or a primitive value.
module.exports assignment:
Import Requirements
Modules exporting a value viaexport = cannot be imported using standard ES6 import syntax (e.g., import Calc from "./calculator") under default compiler settings.
By default, TypeScript requires a corresponding, TypeScript-specific import syntax: import ... = require(...).
export = assignment using standard ES6 default imports (import Calculator from "./calculator"), specific compiler flags in tsconfig.json must be utilized:
allowSyntheticDefaultImports: Setting this totrueinstructs the TypeScript typechecker to allow the ES6 default import syntax. However, it does not change the emitted JavaScript. If the code is compiled to CommonJS and executed in Node.js without a bundler, it will crash at runtime because the emitted JavaScript will attempt to access a.defaultproperty that does not exist.esModuleInterop: To safely execute this pattern in CommonJS, this flag must be enabled. It automatically enablesallowSyntheticDefaultImportsfor the typechecker and instructs the compiler to emit the__importDefaultruntime helper. This helper ensures the emitted JavaScript correctly resolves the module root at runtime, preventing crashes.
Technical Constraints
- Mutual Exclusivity: A module utilizing
export =cannot contain any other ES6 exports (named or default). The export assignment claims the entire module namespace.
- Declaration Merging: To export multiple entities using
export =via identifiers, developers must leverage TypeScript’s declaration merging (e.g., merging a namespace with a class or function) or export a single aggregate object expression.
Master TypeScript with Deep Grasping Methodology!Learn More





