Re-Export Type-Only Imports
What you'll learn: How re-exporting types without type modifiers causes runtime errors in isolated transpilation.
When you work with isolatedModules enabled (which most modern bundlers require), TypeScript enforces an important rule about re-exporting types: you must preserve type-only semantics when re-exporting.
The Problem
When a bundler transpiles your TypeScript files one at a time, it can't perform cross-file analysis. If you import a type and then re-export it without explicitly marking it as type-only, the bundler doesn't know whether it's importing a type or a value.
This creates a dangerous situation: the bundler might generate runtime import code for something that only exists at compile-time, leading to runtime errors.
The Breaking Pattern
// types.ts
export type User = { name: string };
// intermediate.ts
import { User } from './types';
export { User }; // ❌ Error with isolatedModules!
The bundler sees export { User } and thinks "I need to import and re-export this value at runtime." But User is only a type — it has no runtime representation. Your code will crash.
The Fix
Mark your re-export as type-only:
// intermediate.ts
import type { User } from './types';
export type { User }; // ✅ Safe for isolated transpilation
Now the bundler knows this is compile-time only and won't generate runtime import code.
Think of it like this: Without the type modifier, you're writing instructions that could mean "move this furniture" (runtime) or "remember this furniture exists" (compile-time). The bundler can't tell which you mean, so it assumes runtime and breaks. The type modifier is your way of saying "this is just a note, not actual furniture."
Key Takeaway: When using isolatedModules, always use export type when re-exporting type-only imports to prevent runtime errors from bundlers that can't perform cross-file analysis.