Babel-based builds
A project uses Babel or another single-file transpiler for JavaScript output while TypeScript performs type checking.
TypeScript · Const
isolatedModules makes TypeScript report code that cannot be safely transpiled one file at a time. It is designed for pipelines using single-file transformers such as Babel or transpileModule.
Enable this compiler option when TypeScript files may be transpiled independently by tools such as Babel or by transpileModule. TypeScript then reports constructs whose correct JavaScript output requires whole-program type information, while leaving normal type-checking and emitting behavior unchanged.
{"compilerOptions":{"isolatedModules":true}}| Name | Type | Description |
|---|---|---|
isolatedModules | boolean | Whether to report source constructs that cannot be safely transpiled one file at a time. |
Compiler diagnostics for code that requires cross-file type information during transpilation; it does not alter emitted output behavior.
// types.ts
export interface User {
name: string;
}
// main.ts
import type { User } from "./types";
export const greet = (user: User): string => `Hello, ${user.name}`;
The import is explicitly type-only, so a single-file transpiler can remove it without accidentally emitting a runtime import.
A project uses Babel or another single-file transpiler for JavaScript output while TypeScript performs type checking.
A build tool calls TypeScript’s transpileModule API instead of compiling the complete program.
A large codebase wants diagnostics for source patterns that depend on whole-program type information.
It is a compiler option that checks whether each file can be safely transformed without relying on the complete program’s type information. It is useful with Babel and TypeScript’s transpileModule API, which process files independently. The option reports problematic patterns but does not otherwise change checking or emitting behavior.
Follow-up: What problem does it address that ordinary type checking may miss? A program can type-check while a single-file emitter still produces invalid runtime JavaScript for constructs such as type-only exports, namespaces, or ambient const-enum references.
A type-only import explicitly states that the imported name exists only for type analysis. This lets a single-file transpiler remove the import confidently instead of guessing whether it represents a runtime value.
Follow-up: How should a mixed type/value import be handled? Keep the value import as a normal import and mark only the type bindings with type-only syntax, using the supported import syntax for the project’s TypeScript version.
With this option enabled, namespaces are permitted only in files that are modules, meaning the file has an import or export. Ambient const-enum member references are also rejected because their replacement requires information unavailable to a single-file transpiler.
Follow-up: Does the namespace restriction apply to declaration files? No; the documentation specifically excludes .d.ts files from that restriction.
transpileModuleconst enumnamespacetype-only imports and exportsverbatimModuleSyntax