TypeScript Technology & Digital Tools 4 — Questions and Answers
Question 1: Which Jest configuration is needed to run TypeScript tests without a separate compile step?
- ts-jest or babel-jest with @babel/preset-typescript (Correct answer)
- jest-typescript
- tsc-jest
- type-jest
Correct answer: ts-jest or babel-jest with @babel/preset-typescript
`ts-jest` or `babel-jest` with the TypeScript preset transforms `.ts` files on-the-fly so Jest can execute them.
Question 2: What does the `moduleResolution` option `bundler` (added in TypeScript 5.0) enable?
- CommonJS-style resolution
- Resolution logic matching modern bundlers like Vite and esbuild, supporting package.json exports (Correct answer)
- Node 10-style resolution
- Resolution of `.d.ts` files only
Correct answer: Resolution logic matching modern bundlers like Vite and esbuild, supporting package.json exports
`moduleResolution: bundler` aligns TypeScript's import resolution with tools like Vite and webpack that use `package.json` `exports` fields.
Question 3: Which tool can automatically add missing `@types/*` packages to a project based on imported modules?
- typesync (Correct answer)
- typecheck
- dts-gen
- typedoc
Correct answer: typesync
`typesync` scans your `package.json` dependencies and installs any missing `@types/*` packages from DefinitelyTyped.
Question 4: What is the advantage of using `esbuild` over `tsc` for production builds in large TypeScript projects?
- esbuild performs full type checking
- esbuild transpiles TypeScript significantly faster by stripping types without type checking (Correct answer)
- esbuild supports decorators natively
- esbuild generates smaller declaration files
Correct answer: esbuild transpiles TypeScript significantly faster by stripping types without type checking
esbuild is written in Go and strips TypeScript types without running the type checker, making builds 10-100× faster than `tsc`.
Question 5: What does the `composite` option in `tsconfig.json` enable?
- Enables project references and incremental builds across multiple TypeScript subprojects (Correct answer)
- Composes multiple tsconfig files
- Enables strict mode across all files
- Creates composite type unions automatically
Correct answer: Enables project references and incremental builds across multiple TypeScript subprojects
`composite: true` is required for TypeScript project references, enabling incremental builds that only recompile changed subprojects.
Question 6: Which command generates TypeScript declaration files from an existing JavaScript library?
- tsc --declaration
- npx dts-gen -m <module-name> (Correct answer)
- typegen --module
- ts-node --dts
Correct answer: npx dts-gen -m <module-name>
`dts-gen` inspects a JavaScript module at runtime and generates a starter `.d.ts` declaration file.
Question 7: What is `TypeDoc` used for in a TypeScript project?
- Type-checking at runtime
- Generating HTML API documentation from TypeScript source code and JSDoc comments (Correct answer)
- Validating JSON schemas against TypeScript types
- Running end-to-end tests
Correct answer: Generating HTML API documentation from TypeScript source code and JSDoc comments
TypeDoc parses TypeScript source and JSDoc annotations to produce browsable API reference documentation.
Which Jest configuration is needed to run TypeScript tests without a separate compile step?