TypeScript Technology & Digital Tools 2 — Questions and Answers
Question 1: Which TypeScript compiler option enables strict null checks to prevent `null` and `undefined` from being assigned to other types?
- noImplicitAny
- strictNullChecks (Correct answer)
- strictFunctionTypes
- noUnusedLocals
Correct answer: strictNullChecks
`strictNullChecks` makes `null` and `undefined` distinct types that must be handled explicitly.
Question 2: What does the `tsc --watch` command do in a TypeScript project?
- Compiles TypeScript once and exits
- Watches files for changes and recompiles automatically (Correct answer)
- Runs TypeScript tests in watch mode
- Starts a TypeScript language server
Correct answer: Watches files for changes and recompiles automatically
`tsc --watch` continuously monitors source files and recompiles whenever a change is detected.
Question 3: Which tool is commonly used alongside TypeScript to bundle modules for browser delivery?
- Babel
- Webpack (Correct answer)
- Nodemon
- ts-node
Correct answer: Webpack
Webpack is a popular module bundler that processes TypeScript (via loaders) and packages code for browser use.
Question 4: What is the purpose of `ts-node` in a development workflow?
- It transpiles TypeScript to ES3
- It runs TypeScript files directly in Node.js without a separate compile step (Correct answer)
- It lints TypeScript code
- It generates type declaration files
Correct answer: It runs TypeScript files directly in Node.js without a separate compile step
`ts-node` executes TypeScript source directly by compiling it on-the-fly in memory.
Question 5: Which `tsconfig.json` option specifies the ECMAScript target version for the compiled output?
- module
- lib
- target (Correct answer)
- outDir
Correct answer: target
The `target` option tells the TypeScript compiler which JavaScript syntax version to emit (e.g., `ES6`, `ES2020`).
Question 6: What role does ESLint play when integrated with a TypeScript project?
- It compiles TypeScript to JavaScript
- It statically analyzes code for potential errors and style violations (Correct answer)
- It manages TypeScript package versions
- It generates `.d.ts` declaration files
Correct answer: It statically analyzes code for potential errors and style violations
ESLint with `@typescript-eslint` plugins performs static analysis on TypeScript code to catch bugs and enforce coding standards.
Question 7: Which VS Code feature is powered by the TypeScript Language Server and provides inline type information?
- Git blame annotations
- IntelliSense code completion and hover types (Correct answer)
- Terminal integrated shell
- Live Share collaboration
Correct answer: IntelliSense code completion and hover types
IntelliSense uses the TypeScript Language Server to provide autocompletion, parameter hints, and hover-over type information.
Which TypeScript compiler option enables strict null checks to prevent `null` and `undefined` from being assigned to other types?