What isolatedModules enforces and why bundlers need it
Single-file transpilation constraints.
isolatedModules forbids features needing cross-file type info because Babel and esbuild compile each file alone; const enums, certain re-exports, and namespace tricks are flagged.
WHAT THIS TESTS Whether you understand the difference between a whole-program compiler and a single-file transpiler, and why that difference forces certain TypeScript features off when bundlers do the transpilation.
A GOOD ANSWER COVERS Babel and esbuild transpile each file independently and very fast, simply erasing types without consulting a full type checker or other files. That works only if every file can be correctly transformed in isolation. Some TypeScript features need information that lives in other files or in the type system, so a per-file transpiler would emit wrong code for them. The isolatedModules flag does not change emitted output itself; it tells tsc to report an error whenever you write a construct that cannot be safely compiled one file at a time, so problems are caught in your editor and CI rather than producing subtly broken bundles. Disallowed or flagged patterns include const enums, which rely on inlining values the single-file transpiler cannot see; re-exporting a type without the export type form, since the transpiler cannot tell a type from a value to elide it; and certain namespace features and non-module files.
COMMON WRONG ANSWERS Saying it speeds up compilation directly; it is a correctness guard, not an optimizer. Thinking it changes the JavaScript tsc emits. Believing it disables all enums rather than const enums. Forgetting the type-only import and export requirement it encourages.
LIKELY FOLLOW-UPS Why are const enums specifically problematic? What is verbatimModuleSyntax and how does it relate? How do export type and import type satisfy the flag? Does it affect runtime behavior?
ONE CONCRETE EXAMPLE A project bundled with esbuild enables isolatedModules. A developer writes const enum Color { Red, Green } and tsc flags it, because esbuild compiling that file alone cannot inline Color.Red across the codebase, which is the whole point of a const enum. They switch to a regular enum or a plain object map. Likewise, export { SomeType } from './types' is flagged until rewritten as export type { SomeType }, so the transpiler knows to erase it.
Read the original → typescriptlang.org
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.