Skip to main content
This lesson covers importing and exporting in TypeScript, configuring imports for modern build targets, and best practices for organizing a TypeScript project for readability and reuse. Learn how to structure modules, select the right export strategy, and use common import syntaxes that work with ECMAScript modules (ESM).
A horizontal three-step timeline slide about TypeScript showing step 01 (Importing in TypeScript) highlighted in teal, step 02 (Configuring TypeScript) in gray, and step 03 (TypeScript Project — Best Practices).
Why import?
  • Importing breaks a large codebase into smaller, focused modules so code is easier to read, test, and maintain.
  • It enables code reuse across files and packages and helps prevent name collisions when combined with aliasing or namespaces.
Common ESM import syntaxes in TypeScript
Your editor (for example VS Code) will usually auto-complete and insert import statements for you. Rely on that to avoid manual errors.
Project example: module files (under ./import-examples)
  • mathUtils.ts — named exports
  • utils.ts — named exports
  • calculator.ts — default export
Entry point (index.ts) — examples of different import styles and usage:
Quick notes and best practices
  • Aliasing: import { add as sum } from './import-examples/mathUtils'; helps avoid naming collisions when multiple modules export the same symbol name.
  • Namespace imports: import * as utils from './import-examples/utils'; are useful when you want a single object to group all exports (good for utility libraries).
  • Default exports: Use export default when the module exports one primary value; use named exports when a module exports multiple utilities.
  • Prefer named exports for libraries you expect to tree-shake and for clearer IDE auto-completion.
  • Keep module responsibilities small — one concept or small set of related utilities per file.
When your framework expects an exported entry point If your runtime or framework requires an exported function from the entry file (for example index.ts or main.ts), you can provide either a default export or named exports depending on the framework’s convention. Examples:
ESM vs CommonJS
  • ECMAScript modules (ESM) — import / export — are the recommended approach for modern TypeScript projects and for native support in bundlers and Node (with proper configuration).
  • CommonJS — require() / module.exports — is legacy and still used in some Node ecosystems. If interoperating with CommonJS packages, you may need esModuleInterop or allowSyntheticDefaultImports in your tsconfig.json.
Comparison table — default vs named exports Links and references This concludes the section on importing and exporting in TypeScript.

Watch Video