ES Modules (named vs default), re-exports
Understand named vs default exports/imports and how to re-export to build tidy module boundaries.
Intro
Goal: Use ES Modules confidently. You will export/import named and default symbols, then compose them with re-exports for tidy public APIs.
Named exports/imports
Named exports use export before declarations; import them with braces: import { name }.
// file: math.ts
export function add(a: number, b: number): number { return a + b }
export const PI = 3.14159
// file: app.ts
import { add, PI } from "./math"
console.log(add(2, 3), PI) // 5 3.14159All lessons in this course
- ES Modules (named vs default), re-exports
- Ambient declarations (.d.ts) & third-party typings
- Path mapping & module resolution