TypeScript Project Planning & Execution 5 — Questions and Answers
Question 1: Your team wants to enforce that no `any` types are used anywhere in the codebase via CI. Which ESLint rule from `@typescript-eslint` enforces this?
- @typescript-eslint/no-explicit-any (Correct answer)
- @typescript-eslint/strict-boolean-expressions
- @typescript-eslint/ban-types
- @typescript-eslint/no-unsafe-assignment
Correct answer: @typescript-eslint/no-explicit-any
`@typescript-eslint/no-explicit-any` flags any usage of the `any` type, encouraging proper typing throughout the codebase.
Question 2: In a TypeScript monorepo with project references, what command rebuilds only packages whose sources changed since the last build?
- tsc --all
- tsc -b --force
- tsc -b (Correct answer)
- tsc --watch --incremental
Correct answer: tsc -b
`tsc -b` (build mode) reads project references and only recompiles packages with changed sources using `.tsbuildinfo` cache files.
Question 3: When adding a new team member to a TypeScript project, which file should they check first to understand the compiler configuration and strictness level?
- package.json
- .eslintrc.json
- tsconfig.json (Correct answer)
- .babelrc
Correct answer: tsconfig.json
`tsconfig.json` defines the TypeScript compiler options including strictness flags, target environment, and module resolution strategy.
Question 4: Which approach is recommended when a TypeScript project needs to share type definitions between a frontend and backend in a monorepo?
- Copy-paste type definitions into both packages
- Create a shared `types` package referenced by both frontend and backend (Correct answer)
- Use `any` on the boundary to avoid coupling
- Generate types from the backend's runtime values using typeof
Correct answer: Create a shared `types` package referenced by both frontend and backend
A shared `types` package ensures the frontend and backend agree on data shapes, catching type mismatches at compile time.
Question 5: A developer needs to run TypeScript files directly in Node.js without a compile step during development. Which tool enables this?
- tsc --watch
- ts-node or tsx (Correct answer)
- node --experimental-vm-modules
- nodemon with babel
Correct answer: ts-node or tsx
`ts-node` (or the faster `tsx`) registers a TypeScript compiler hook in Node.js so `.ts` files execute directly without explicit compilation.
Question 6: Which strategy reduces TypeScript compilation time in a large project by skipping type checking of all `.d.ts` files from node_modules?
- noLib: true
- skipLibCheck: true (Correct answer)
- noResolve: true
- typeRoots: []
Correct answer: skipLibCheck: true
`skipLibCheck: true` skips type checking of declaration files in node_modules, significantly speeding up compilation in large projects.
Question 7: When planning TypeScript adoption for an existing team, what is the most effective first step to reduce friction?
- Enable all strict flags immediately to catch all errors at once
- Rename all .js files to .ts and fix every error before merging
- Add TypeScript with lenient settings and tighten rules incrementally over sprints (Correct answer)
- Rewrite the project from scratch in TypeScript
Correct answer: Add TypeScript with lenient settings and tighten rules incrementally over sprints
Starting with lenient TypeScript settings and progressively enabling stricter rules allows the team to adopt typing without blocking velocity.
Your team wants to enforce that no `any` types are used anywhere in the codebase via CI.
Which ESLint rule from `@typescript-eslint` enforces this?