Navigate ESM vs CJS interop, .d.ts declaration files, tsconfig paths mapping, barrel file trade-offs, and verbatimModuleSyntax.
0 / 5 completed
1 / 5
What is the difference between ES modules and CommonJS in TypeScript/Node.js?
ESM vs CJS: TypeScript emits either format based on module in tsconfig.json. Node.js distinguishes them via .mjs/.cjs extensions or the "type": "module" package.json field. Dual-format packages ship both, but authoring them correctly requires careful export map configuration to avoid the "dual-package hazard."
2 / 5
What are TypeScript declaration files (.d.ts) and what purpose do they serve?
.d.ts files: when you compile a TypeScript library with declaration: true, the compiler emits .d.ts files alongside the JavaScript. Consumers get type information without access to the source. The @types/* packages on npm provide community-maintained declarations for popular JavaScript-only libraries.
3 / 5
What does paths mapping in tsconfig.json configure?
paths mapping: helps avoid deeply nested relative imports. Important caveat: TypeScript's paths are only for type checking — the compiler does NOT rewrite imports at emit time. Bundlers (Webpack, Vite) or Node.js (--experimental-specifier-resolution) must be separately configured with matching aliases.
4 / 5
What is a barrel file in TypeScript and what is its main drawback?
Barrel files: convenient but costly. A barrel that re-exports 200 components forces the TypeScript language server to process all 200 files to resolve any import from it. In large monorepos this causes noticeable IDE slowness. Solutions include granular imports, verbatimModuleSyntax, or build tools that rewrite barrel imports to direct paths.
5 / 5
What does verbatimModuleSyntax in TypeScript 5 enforce?
verbatimModuleSyntax: without it, import { SomeType } from "./types" might emit a side-effectful runtime import even though only a type is used. With the flag, the compiler requires import type { SomeType } from "./types", which is always fully erased. This prevents accidental module execution in environments where only types were intended.