Skip to main content
Module 9 · Lesson 3 of 320/22 in the course~16 min
Module lessons (3/3)

Modular Architecture, Barrel Files & API Contracts

Lesson preview5 hands-on exercises readyCourse TypeScript · Module 9 — Error Handling, Result Pattern & Architecture

Separate import types for tree-shaking, avoid circular dependencies, and publish stable interfaces.

What you'll learn in this lesson

  • Separate type-only imports (import type { User }) from runtime imports to facilitate tree-shaking and isolatedModules.
  • Understand why enabling verbatimModuleSyntax prevents hidden circular imports and ghost side-effects.
  • Balance the use of barrel files (index.ts) without compromising build speed or creating dependency loops.
  • Clearly separate Public Types / DTOs from the internal persistence details of a module.

Overview

As a code base grows beyond a few dozen files, the quality of the design depends as much on the architecture of the module boundaries as it does on the individual types within the functions. TypeScript offers specific tools to keep types and execution clean in modern bundlers.

When a bundler like Vite, esbuild or SWC compiles a single file at a time (isolatedModules: true), it doesn't know whether a symbol imported from another file is an interface (to be deleted) or a class/constant (to be kept at runtime!).

Sections covered in this lesson

  1. 1import type, export type and verbatimModuleSyntax
  2. 2Barrel Files: Scale opportunities and pitfalls
  3. 3Guided practice
  4. 4Check for understanding
Pro Lesson · Module 9 — Error Handling, Result Pattern & Architecture

Unlock "Modular Architecture, Barrel Files & API Contracts" and the full Course TypeScript curriculum

Separate import types for tree-shaking, avoid circular dependencies, and publish stable interfaces.

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in Course TypeScript plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.