Question presented to candidate:
"Your team just turned on verbatimModuleSyntax and the build is full of TS1484 errors. What does that flag actually enforce, what was wrong with the old importsNotUsedAsValues and preserveValueImports settings, and what does the emitted JavaScript look like now?"
What a strong answer should cover:
- Import elision: by default tsc removes imports whose names are only used as types, and it needs the type checker (and the other file) to decide that
- Why that breaks single-file transpilers (Babel, esbuild, swc,
transpileModule) and can silently drop a side-effect import - The rule of
verbatimModuleSyntax: anything markedtypeis erased, everything else is emitted exactly as written; a type imported withouttypeis error TS1484, a re-exported type withoutexport typeis TS1205 - What it replaced:
importsNotUsedAsValues(remove / preserve / error) andpreserveValueImports, which interacted confusingly withisolatedModules; TypeScript 5.0 deprecated both (TS5101) in favour of the new flag - Side effects of the flag: it implies
isolatedModules, keepsimport {} from "x"for inline type-only imports, and forbids ESM syntax in files that emit CommonJS (TS1286)
Code / implementation expected: Yes β a file with a mixed import, the emit before and after the flag, and the fixed import type / inline type forms.