0Pricing
TypeScript Academy · Lesson

Re-exports and Barrel Files

Create index files to simplify import paths.

Welcome

Barrel files (index.ts) aggregate and re-export module contents, creating a simple public API for a directory so consumers have cleaner import paths.

What Is a Barrel File

A barrel is an index.ts that re-exports everything from the same directory. Consumers import from the directory instead of individual files.
// src/models/index.ts (barrel)
export { User } from './user';
export { Product } from './product';
export { Order } from './order';

All lessons in this course

  1. ES Module Syntax: import and export
  2. Re-exports and Barrel Files
  3. Type-Only Imports and Exports
  4. Namespaces vs Modules: Modern Usage
← Back to TypeScript Academy