Question presented to candidate:
"Your team wants to move a TypeScript library from tsc to tsdown so declaration files are generated by oxc. What changes in how you write the code, and how do you make sure the published types stay the same?"
What a strong answer should cover:
- The switch: tsdown generates declarations through rolldown-plugin-dts, which picks its oxc generator when
compilerOptions.isolatedDeclarationsis enabled (tsc otherwise); oxc copies types from syntax and never runs a checker - The authoring rules: explicit return types on exported functions and methods, annotations on exported variables set from calls or
new, typed parameters with non-literal defaults, named default exports; literals, literal objects andas conststay unannotated - Writing the same type inference produced, not a wider one:
Record<string, string>instead ofas constsilently loses keys,anypasses and ruins the API;thisfor fluent methods, generics spelled out - The traps found by running both tools:
satisfiesis rejected by tsc but accepted by oxc,typeofa local pulls the local into the.d.ts, spreads and computed keys need explicit types - The safety net: keep
tsc --noEmitwithisolatedDeclarationsas the CI gate, diff the emitted.d.tsbefore and after, and check the package with attw
Clarifying questions expected:
- Is this a library that publishes
.d.tsfiles, or an app (where the flag rarely pays off)? - How big is the public API, and is a monorepo build waiting on declaration emit?
Code / implementation expected: Yes β rewrite a few failing exports so they pass, and show that the public types are unchanged.