Skip to main content
The Export API provides tools for managing exports and module boundaries in TypeScript codebases.
Exports are a TS-only language feature

Export Statements vs Exports

Similar to imports, Codegen provides two levels of abstraction for working with exports:
  • ExportStatement - Represents a complete export statement
  • Export - Represents individual exported symbols
You can access these through your file’s collections:
ExportStatement inherits from Statement, providing operations like remove() and insert_before(). This is particularly useful when you want to manipulate the entire export declaration.

Common Operations

Here are common operations for working with exports:
When adding exports, you can:
  • Add from source code with add_export_from_source()
  • Export existing symbols with add_export()
  • Re-export from other files by specifying from_file
The export will automatically handle adding any required imports.

Export Types

Codegen supports several types of exports:

Identifying Export Types

The Export API provides methods to identify and filter exports:

Export Resolution

You can trace exports to their original symbols:

Managing Re-exports

You can manage re-exports with the TSExport.is_reexport() API:
When managing exports, consider the impact on your module’s public API. Not all symbols that can be exported should be exported.