TypeScript Technology & Digital Tools 5 — Questions and Answers
Question 1: In a monorepo setup using npm workspaces, how do you reference a local TypeScript package from another workspace package?
- Using a relative `../../` import path directly
- Listing it as a dependency with its package name and using TypeScript project references (Correct answer)
- Copying `.d.ts` files manually between packages
- Using `require()` with an absolute path
Correct answer: Listing it as a dependency with its package name and using TypeScript project references
npm workspaces symlink local packages by name, and TypeScript project references (`references` in tsconfig) wire up type checking across them.
Question 2: Which GitHub Actions step is typically added to enforce TypeScript type safety in a CI workflow?
- run: npm test
- run: npx tsc --noEmit (Correct answer)
- run: npm run lint
- run: npm run build
Correct answer: run: npx tsc --noEmit
Running `tsc --noEmit` in CI ensures that type errors block merges without producing any output artifacts.
Question 3: What does `@ts-expect-error` do when placed above a line of TypeScript code?
- Suppresses all TypeScript errors in the file
- Expects the next line to produce a type error and reports a new error if it does not (Correct answer)
- Disables strict mode for one line
- Marks code as deprecated
Correct answer: Expects the next line to produce a type error and reports a new error if it does not
`@ts-expect-error` is the preferred alternative to `@ts-ignore` because it fails if the suppressed error disappears, keeping suppressions intentional.
Question 4: Which tool is used to ensure consistent TypeScript versions across team members in a project?
- nvm
- Volta
- npm engines field + lockfile (Correct answer)
- ts-node
Correct answer: npm engines field + lockfile
Declaring `"typescript": "x.x.x"` in `devDependencies` and committing `package-lock.json` pins the TypeScript version for all contributors.
Question 5: What is the role of the `lib` array in `tsconfig.json`?
- Lists library files to bundle with the output
- Specifies built-in API type definitions (e.g., DOM, ES2020) included in compilation (Correct answer)
- Defines paths to third-party type files
- Controls which node_modules are type-checked
Correct answer: Specifies built-in API type definitions (e.g., DOM, ES2020) included in compilation
The `lib` option controls which built-in type definitions are available, such as `DOM` for browser APIs or `ES2020` for modern JavaScript globals.
Question 6: Which Prettier option, when set to `"all"`, adds trailing commas to multi-line TypeScript function parameters?
- bracketSpacing
- trailingComma (Correct answer)
- semi
- singleQuote
Correct answer: trailingComma
Setting `trailingComma: "all"` in Prettier config adds trailing commas to function parameters, object literals, and array elements in multi-line contexts.
Question 7: What does `isolatedModules: true` in `tsconfig.json` enforce?
- Each file must be a module (no global scripts)
- Each file can be safely transpiled in isolation without cross-file type information (Correct answer)
- Type imports must use `import type` syntax
- Modules cannot import from node_modules
Correct answer: Each file can be safely transpiled in isolation without cross-file type information
`isolatedModules` ensures compatibility with single-file transpilers like Babel or esbuild that cannot use cross-file type data.
In a monorepo setup using npm workspaces, how do you reference a local TypeScript package from another workspace package?