tsconfig and Tooling Interview Questions

Explain target, lib, module and moduleResolution.

  • target: which JavaScript syntax is emitted (down-levels newer syntax).
  • lib: which built-in API types exist (ES2023, DOM). It does not add polyfills.
  • module: output module format (commonjs, esnext, nodenext).
  • moduleResolution: how imports are found (bundler for Vite/Next.js, nodenext for Node).

What is a .d.ts file and what is module augmentation?

A declaration file contains only types describing JavaScript code (generated with declaration: true, shipped by packages, or from @types/*). Module augmentation re-opens a module's interfaces to add members, using interface merging: for example adding user to Express' Request or role to the NextAuth Session, inside declare module "..." { interface ... }.

What does isolatedModules do and why do Next.js and Vite require it?

Those tools transpile each file independently with esbuild/SWC and never see other files. isolatedModules makes tsc report code that cannot be compiled file by file: re-exporting types without export type, using another file's const enum, or non-module files. Because those tools only strip types, you also need tsc --noEmit in CI to actually check types.

How would you migrate a large JavaScript codebase to TypeScript?

Incrementally: add tsconfig.json with allowJs and non-strict settings; add tsc --noEmit to CI; convert leaf modules (utils, types, API clients) first; type external boundaries (API responses, DB models); turn on strict flags one at a time; use @ts-expect-error with a ticket for hard cases instead of any; ban any with typescript-eslint; finish with strict: true and allowJs: false.