TypeScript Project Planning & Execution 2 — Questions and Answers
Question 1: Which `tsconfig.json` option enforces that all switch statement cases are exhaustively handled using never-type checks?
- noImplicitReturns
- strictNullChecks
- noFallthroughCasesInSwitch (Correct answer)
- useUnknownInCatchVariables
Correct answer: noFallthroughCasesInSwitch
`noFallthroughCasesInSwitch` causes a compiler error when a switch case falls through to the next without a break or return.
Question 2: When migrating a large JavaScript project to TypeScript incrementally, which file extension should you use to allow importing JS files without type errors?
- .tsx
- .d.ts
- allowJs: true in tsconfig (Correct answer)
- .mts
Correct answer: allowJs: true in tsconfig
Setting `allowJs: true` in tsconfig.json lets TypeScript include and type-check JavaScript files alongside TypeScript files during migration.
Question 3: Your team wants TypeScript to emit no JavaScript output but still type-check the project. Which tsconfig option achieves this?
- noEmit: true (Correct answer)
- declaration: false
- isolatedModules: true
- emitDeclarationOnly: true
Correct answer: noEmit: true
`noEmit: true` instructs TypeScript to perform type checking without writing any output files.
Question 4: Which monorepo tool uses TypeScript project references (`composite: true`) to enable incremental builds across packages?
- Lerna
- Nx
- Turborepo
- tsc --build mode (Correct answer)
Correct answer: tsc --build mode
`tsc --build` (or `tsc -b`) mode reads project references in tsconfig and builds only changed packages incrementally.
Question 5: A CI pipeline should fail when new TypeScript errors are introduced. Which command exits with a non-zero code on type errors without emitting files?
- tsc --watch
- tsc --noEmit (Correct answer)
- tsc --strict
- tsc --declaration
Correct answer: tsc --noEmit
`tsc --noEmit` type-checks the project and returns a non-zero exit code if errors exist, making it ideal for CI gates.
Question 6: Which `paths` alias configuration in `tsconfig.json` lets you import `@utils/logger` instead of `../../utils/logger`?
- "paths": { "@utils/*": ["src/utils/*"] } (Correct answer)
- "baseUrl": "@utils"
- "rootDir": "utils"
- "moduleResolution": "bundler"
Correct answer: "paths": { "@utils/*": ["src/utils/*"] }
The `paths` compiler option maps import aliases to file system paths, enabling cleaner import statements.
Question 7: When using TypeScript with ESModules and `"type": "module"` in package.json, what file extension must TypeScript output files use for Node.js compatibility?
- .ts
- .cjs
- .mjs (Correct answer)
- .jsx
Correct answer: .mjs
Node.js treats `.mjs` files as ES modules; when emitting native ESM, TypeScript must output `.mjs` extensions.
Which `tsconfig.json` option enforces that all switch statement cases are exhaustively handled using never-type checks?