Question presented to candidate:
"Some projects write import { twice } from \"./math.ts\" with the .ts extension. What does allowImportingTsExtensions actually allow, why does tsc insist on noEmit or emitDeclarationOnly with it, and when is this a good idea?"
What a strong answer should cover:
- Without the flag, a value import ending in
.ts,.mtsor.ctsis TS5097; with it, tsc accepts the path and type-checks against the source file - tsc never rewrites import paths (before 5.7), so emitted JavaScript would keep
"./math.ts"and fail to load; that is why the flag requiresnoEmitoremitDeclarationOnly(TS5096) - It fits setups where something else runs or builds the
.tsfiles: Vite or esbuild withmoduleResolution: "bundler", Bun, Deno, and Node.js type stripping import typewith a.tspath is allowed even without the flag; importing a.d.tspath as a value is TS2846- Emitted
.d.tsfiles keep the.tsspecifiers;.jsspecifiers still work alongside - TypeScript 5.7 added
rewriteRelativeImportExtensions, which rewrites./math.tsto./math.jsin the output, for projects that do want tsc to emit JavaScript
Code / implementation expected: Optional β a tsconfig with the flag and noEmit, and an import that needs it.