Sample questions
Question 1Easy
What does "strict": true in tsconfig.json do?
- Makes the emitted JavaScript use strict mode only
- Disables the any type throughout the project
- Enables a family of strict type-checking flags
- Stops the compiler emitting files with type errors
Answer: C. Enables a family of strict type-checking flags
Explanation
strict is an umbrella for flags such as strictNullChecks, noImplicitAny, strictFunctionTypes and strictPropertyInitialization.
Step-by-step solution
- The strict setting is an umbrella setting in tsconfig.json.
- It turns on a family of strict checks, such as strictNullChecks, noImplicitAny and strictFunctionTypes.
- So it enables a group of strict type-checking flags (option C).
Why the other options are wrong
- A. Its main effect is on type checking, not on the emitted mode alone.
- B. Any is still allowed; noImplicitAny only stops implicit any.
- D. Type errors are still reported and output is still emitted by default.
Tip: Strict is shorthand for a set of flags; each flag can be turned off on its own.
Question 2Easy
What does the "module" option in tsconfig.json control?
- Whether each file must contain an export
- The folder used to resolve node_modules
- Which modules are allowed to import each other
- The module format of the emitted code
Answer: D. The module format of the emitted code
Explanation
module chooses how import and export are written in the output, for example as require calls (CommonJS) or as ES module syntax.
Step-by-step solution
- tsconfig "module" sets the module system for emitted JavaScript.
- Values include commonjs, esnext and nodenext.
- It does not change which files can import each other.
Why the other options are wrong
- A. Exports are not required by this option.
- B. Resolution of folders is moduleResolution and related options.
- C. There is no such access control.
Tip: module = output format.
Question 3Easy
What does tsc --noEmit do?
- Deletes the previous build output
- Type-checks the project but writes no files
- Writes JavaScript files but skips the .d.ts files
- Compiles but skips all type checking
Answer: B. Type-checks the project but writes no files
Explanation
--noEmit is used in CI or alongside bundlers that do the compilation themselves, so tsc only reports type errors.
Step-by-step solution
- --noEmit tells tsc not to write output files.
- It still performs type checking.
- It is often used in CI to check types only.
Why the other options are wrong
- A. It never deletes anything.
- C. No files are written at all, including .d.ts.
- D. Type checking still runs.
Tip: noEmit = check only.
Question 4Easy
What does the "target" option in tsconfig.json control?
- Which JavaScript version the output is written in
- Which runtime environment the type checker simulates
- Which folder the compiled files are written to
- Which files are included in compilation
Answer: A. Which JavaScript version the output is written in
Explanation
target sets the language level of the emitted JavaScript; newer syntax is down-levelled when the target is older.
Step-by-step solution
- The target option sets the JavaScript language level of the output.
- Newer syntax is converted to older syntax when the target is older.
- So target controls the version of the emitted JavaScript (option A).
Why the other options are wrong
- B. Runtime environments are not set by target; lib sets the built-in typings.
- C. The output folder is set by outDir.
- D. The included files are set by include.
Tip: Target sets the output JavaScript version; lib sets which built-in APIs are typed.
Question 5Medium
With noUncheckedIndexedAccess on, what is the type of first?
const nums: number[] = [1, 2];
const first = nums[0];
- number | null
- 1
- number | undefined
- number
Answer: C. number | undefined
Explanation
This flag adds undefined to element and index-signature reads, because the index might be out of range. It is not included in strict.
Step-by-step solution
- NoUncheckedIndexedAccess adds undefined to reads from arrays and index signatures.
- An index might be out of range, so nums[0] could be undefined.
- So the type of first is number | undefined (option C).
Why the other options are wrong
- A. Null is not added; the flag adds undefined.
- B. The literal 1 is only the value, not the declared type.
- D. Without the flag the type is number; with it undefined is added.
Tip: Turn on noUncheckedIndexedAccess to make index reads include undefined.
Question 6Medium
How does // @ts-expect-error differ from // @ts-ignore?
- It turns the error into a warning
- It errors itself when the next line has no error
- It is only allowed in .d.ts files
- It hides every type error in the whole file
Answer: B. It errors itself when the next line has no error
Explanation
@ts-expect-error documents a deliberate error and alerts you once the error goes away, so stale suppressions don't pile up.
Step-by-step solution
- Both directives suppress the error on the next line.
- @ts-expect-error also reports an error if the next line has no error.
- @ts-ignore never complains, so stale suppressions can pile up unnoticed.
- So expect-error reports itself when the error goes away (option B).
Why the other options are wrong
- A. Neither directive turns an error into a warning.
- C. Both work in ordinary .ts files, not only in declaration files.
- D. Both directives apply only to the next line, not the whole file.
Tip: Prefer @ts-expect-error over @ts-ignore so suppressions are flagged once they are no longer needed.
Question 7Medium
By default, what does tsc do when a file has type errors?
- Emits only the files with no errors
- Stops compiling at the very first error it finds
- Emits nothing for the whole project
- Reports them and still emits the JavaScript
Answer: D. Reports them and still emits the JavaScript
Explanation
Type errors do not block output unless noEmitOnError is set, because the JavaScript is usually still runnable.
Step-by-step solution
- By default tsc still writes JavaScript when there are type errors.
- The noEmitOnError option would stop output, but it is off by default.
- So tsc reports the errors and still emits the JavaScript (option D).
Why the other options are wrong
- A. Files are emitted even when errors exist, not only error-free ones.
- B. Tsc reports all errors, not just the first.
- C. Output is still written for the project by default.
Tip: Set noEmitOnError to block output when there are type errors.
Question 8Medium
What problem does esModuleInterop address?
- Loading JSON files with import
- Default imports from CommonJS modules
- Mixing .ts and .js files in one project
- Using ES modules inside the browser
Answer: B. Default imports from CommonJS modules
Explanation
It emits helpers so that import express from "express" works with a module that sets module.exports, matching how bundlers and Node treat CommonJS.
Step-by-step solution
- Some CommonJS modules set module.exports and have no real default export.
- EsModuleInterop emits helpers so that a default import works with them.
- So it addresses default imports from CommonJS modules (option B).
Why the other options are wrong
- A. Importing JSON is handled by a separate resolveJsonModule option.
- C. Mixing .ts and .js files is handled by the allowJs option.
- D. ES modules in the browser are a runtime and bundler matter, not this option.
Tip: Turn on esModuleInterop when a CommonJS package needs a default import.
Question 9Hard
If tsconfig.json maps "@app/" to "src/" with the paths option, what happens to import "@app/db" in the emitted JavaScript?
- It stays as written, so the runtime must resolve it too
- It is replaced by the contents of src/db
- It is rewritten to a relative path such as ./src/db
- It is removed, since paths entries are only types
Answer: A. It stays as written, so the runtime must resolve it too
Explanation
paths only tells the type checker where to find modules. A bundler, a loader or a separate tool must apply the same mapping at runtime.
Step-by-step solution
- Paths only tells the type checker how to resolve '@app/db'.
- The emitted JavaScript still contains the import as written.
- So the runtime must resolve it through a bundler, loader or similar tool (option A).
Why the other options are wrong
- B. The import is not replaced with the file contents; it stays as written.
- C. Tsc does not rewrite the import to a relative path.
- D. The import is not removed; it is still needed at runtime.
Tip: Mirror path aliases in your bundler or runtime, since tsc does not rewrite them.
Question 10Hard
What is printed when the compiled code runs?
const n = "5" as unknown as number;
console.log(n + 1);
- 51
- 6
- NaN
- It throws a TypeError
Answer: A. 51
Explanation
Type assertions are erased and never convert values. At runtime n is still the string "5", so + concatenates.
Step-by-step solution
- The double assertion is erased at compile time and does not convert the value.
- At runtime n is still the string '5'.
- '5' + 1 concatenates to the string '51'.
- console.log prints 51 (option A).
Why the other options are wrong
- B. The + with a string concatenates; it does not add numerically.
- C. NaN only comes from arithmetic on a non-number; here + concatenates strings.
- D. The code does not throw.
Tip: Type assertions never convert values; a string plus a number concatenates in JavaScript.
Practise all 18 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →