Question presented to candidate:
"Transpiling TypeScript to JavaScript can be done one file at a time by fast tools, but generating .d.ts files has always needed tsc. Why is that, and what does the isolatedDeclarations option change?"
What a strong answer should cover:
- Why declaration emit needs a type checker: an unannotated export (a function return type, a variable set from a call) gets its type from inference, which can depend on other files and on the whole program
- What
isolatedDeclarationsdoes (TypeScript 5.5+): it reports an error wherever an export's type cannot be written down from that file's syntax alone, so any tool can produce the.d.tsfile by copying annotations, with no checker - What still needs no annotation ("trivially inferable"): literals, object literals of literals,
as constarrays, type assertions; what does (calls,new, spreads, plain arrays, unannotated returns, parameters with non-literal defaults) and the TS90xx error family - What it does not do: it changes no emit by itself, needs
declarationorcomposite, and tsc writes no.d.tswhile those errors exist - The payoff: per-file, parallel declaration emit (
ts.transpileDeclaration, oxc, bundler plugins) and starting downstream type checks before upstream projects finish
Code / implementation expected: Optional β an exported function that fails under the flag, the error, and the annotated version.