TypeScript 6.0 Type-Only Imports Are Now Enforced: What `verbatimModuleSyntax` Actually Breaks in Real Codebases
TypeScript 6.0 Type-Only Imports Are Now Enforced: What verbatimModuleSyntax Actually Breaks in Real Codebases This article was written with the assistance of AI, under human supervision and review. Most TypeScript build failures after a major version upgrade stem from one assumption: the compiler will figure out which imports are types and which are runtime values. That assumption breaks the…
TypeScript 6.0 has introduced a new feature that enforces explicit type-only imports. This change affects real-world codebases and requires developers to modify their import statements to comply with the new rule. The flag `verbatimModuleSyntax` in tsconfig.json forces the compiler to make no assumptions about import elision and demands explicit declaration of the import type.
When `verbatimModuleSyntax` is enabled, TypeScript treats every import and export statement as either a type-only import or a runtime import. Mixed imports that combine both types and runtime values are no longer allowed and must be split into separate lines to avoid compilation errors.
This change impacts several aspects of codebases:
1. Mixed import statements that import both types and runtime values must be separated into two lines, one for types and another for runtime values. This often requires significant refactoring efforts.
2. Re-exports using `export * from` in barrel files cause failures under `verbatimModuleSyntax` because the compiler cannot determine whether they export types or values. Developers need to split type and value re-exports into separate statements.
3. Side-effect modules that execute code upon import also require explicit syntax, either using `import './module'` or the compiler may treat them as dead code.
The main benefit of this change is deterministic builds, but it requires developers to spend considerable time and effort migrating their codebase to comply with this new rule. Additionally, the flag deprecates three older flags: `importsNotUsedAsValues`, `preserveValueImports`, and `isolatedModules`.
In summary, TypeScript 6.0 enforces explicit type-only imports through the `verbatimModuleSyntax` flag, which breaks existing codebases by requiring developers to refactor their import statements and address issues related to mixed imports, re-exports, and side-effect modules. This migration process is necessary to ensure build determinism, but it comes with significant effort and potential disruptions to development workflows.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.