Split code across files — named, default, and namespace imports and exports, plus type-only imports that disappear from the compiled output.
Why: ES modules split a codebase into files with explicit boundaries. Types travel through imports just like values — use "import type" when you only need the type, so it disappears entirely from the compiled output.
// ── math.ts — named exports ──────────────────────────
export const PI = 3.14159;
export function square(n: number) {
return n * n;
}
export type Point = { x: number; y: number };
// ── user.ts — one default export per file ────────────
export default class User {
constructor(public name: string) {}
}
// ── app.ts — importing it all ────────────────────────
import User from './user'; // default import
import { PI, square, type Point } from './math'; // named + type-only
import * as math from './math'; // namespace import
const p: Point = { x: 2, y: 3 };
console.log(new User('Alice').name, square(p.x), PI === math.PI);