MCQs on TypeScript Compiler and Configuration | TypeScript

Explore advanced TypeScript configuration options with these 30 multiple-choice questions. Dive into tsconfig.json settings, customizing the build process, and working with declaration files and d.ts for robust TypeScript projects.


Topic 1: Advanced tsconfig.json Settings (10 Questions)

  1. Which of the following is the default value for strict in a tsconfig.json file?
    A) true
    B) false
    C) undefined
    D) none
  2. What does the noImplicitAny option in tsconfig.json control?
    A) Ensures that variables must have a type assigned
    B) Allows any type for variables
    C) Disables implicit type inference
    D) Throws errors when any is used
  3. Which tsconfig.json option specifies the target JavaScript version for compilation?
    A) target
    B) module
    C) outDir
    D) lib
  4. In the tsconfig.json, which option allows you to specify the root directory for your TypeScript files?
    A) rootDir
    B) baseUrl
    C) include
    D) files
  5. What does the skipLibCheck option in the tsconfig.json file do?
    A) Skips checking the types of declaration files (.d.ts)
    B) Skips compiling libraries
    C) Skips type checking of user files
    D) Skips library files during bundling
  6. What is the default value of moduleResolution in tsconfig.json?
    A) node
    B) classic
    C) esnext
    D) none
  7. How do you enable TypeScript’s source map generation in the tsconfig.json?
    A) "sourceMap": true
    B) "sourceMap": "true"
    C) "generateSourceMaps": true
    D) "sourceMapping": true
  8. Which option in tsconfig.json controls whether to output the compiled JavaScript to a different directory?
    A) outDir
    B) rootDir
    C) destinationDir
    D) outputDir
  9. In tsconfig.json, what does setting "esModuleInterop": true do?
    A) Allows default import of CommonJS modules
    B) Enables strict mode for ES Modules
    C) Allows imports from external modules
    D) Ensures compatibility with ES6 module syntax
  10. How do you prevent TypeScript from emitting JavaScript files after compilation in tsconfig.json?
    A) "noEmit": true
    B) "emit": false
    C) "generate": false
    D) "noCompile": true

Topic 2: Customizing Build Processes (10 Questions)

  1. How can you specify a custom file for TypeScript’s build output?
    A) Use the --outFile compiler option
    B) Modify the outDir setting in tsconfig.json
    C) Set outputFile in tsconfig.json
    D) Use --output flag in the TypeScript command
  2. Which option can be used to watch for file changes during TypeScript compilation?
    A) --watch
    B) --auto
    C) --watchFiles
    D) --autoCompile
  3. What does the declaration option in tsconfig.json do?
    A) Generates declaration files (.d.ts) for TypeScript files
    B) Specifies the type definitions used in the project
    C) Declares the global variables for the project
    D) Generates JavaScript files
  4. Which of the following options in tsconfig.json allows for incremental compilation?
    A) "incremental": true
    B) "cache": true
    C) "fastCompilation": true
    D) "optimized": true
  5. How do you configure TypeScript to clean up old .tsbuildinfo files?
    A) "cleanUp": true
    B) "removeBuildInfo": true
    C) "tsBuildInfo": false
    D) "deleteOldBuildInfo": true
  6. What does the exclude field in tsconfig.json control?
    A) Files to exclude from compilation
    B) Files to include in the compilation
    C) File extensions to exclude
    D) Files to include in declaration generation
  7. Which TypeScript compiler flag allows specifying the module system to use?
    A) --module
    B) --target
    C) --moduleResolution
    D) --moduleSystem
  8. How can you enable a strict mode that applies a variety of stricter checks?
    A) "strict": true
    B) "strictMode": true
    C) "strictChecks": true
    D) "strictErrors": true
  9. What is the effect of setting the removeComments option to true in tsconfig.json?
    A) Removes comments from the output JavaScript files
    B) Prevents comments from being included in the source
    C) Keeps comments in the declaration files
    D) Removes comments from TypeScript files only
  10. How can you specify multiple root directories in the tsconfig.json?
    A) Use the rootDirs option
    B) Use multiple rootDir options
    C) Use baseDirs option
    D) Use the include field with multiple directories

Topic 3: Declaration Files and d.ts (10 Questions)

  1. What is the primary purpose of declaration files (.d.ts) in TypeScript?
    A) To provide type information for JavaScript libraries
    B) To generate type definitions from TypeScript code
    C) To exclude certain modules from TypeScript compilation
    D) To output JavaScript files from TypeScript
  2. How can you include an external .d.ts file in a TypeScript project?
    A) Use the /// <reference path="file.d.ts" /> directive
    B) Use the import statement
    C) Include it in the include array in tsconfig.json
    D) Both A and C
  3. What happens if you don’t include .d.ts files when using JavaScript libraries in TypeScript?
    A) TypeScript will generate types automatically
    B) TypeScript will treat the libraries as any
    C) TypeScript will throw an error during compilation
    D) TypeScript will ignore the library
  4. What is the correct syntax for declaring a global variable in a .d.ts file?
    A) declare var globalVar: string;
    B) export var globalVar: string;
    C) global var globalVar: string;
    D) declare global { var globalVar: string; }
  5. How do you specify the type of a third-party module using a declaration file?
    A) declare module 'module-name' { export type myType; }
    B) declare module 'module-name' { export default myType; }
    C) module 'module-name' { export type myType; }
    D) export module 'module-name' { type myType; }
  6. What is the correct way to declare a function in a .d.ts file?
    A) declare function myFunction(): void;
    B) export function myFunction(): void;
    C) declare myFunction(): void;
    D) function declare myFunction(): void;
  7. How can you define an interface in a declaration file?
    A) declare interface MyInterface {}
    B) interface MyInterface {}
    C) export interface MyInterface {}
    D) declare type MyInterface = {};
  8. Can you use declare in a .d.ts file to define an external module?
    A) Yes, with the declare module keyword
    B) No, declare is only used for variables
    C) Yes, but only for global modules
    D) No, modules must be declared in the tsconfig.json
  9. In a declaration file, what does the export keyword do?
    A) Makes the declared type or function available for import
    B) Prevents the type or function from being used outside
    C) Declares a module for external usage
    D) Makes the function or variable globally available
  10. What is the correct syntax for importing a .d.ts file in TypeScript?
    A) import './file.d.ts';
    B) import { typeName } from './file.d.ts';
    C) /// <reference path="file.d.ts" />
    D) import 'file.d.ts';

Answer Key

QnoAnswer
1B) false
2A) Ensures that variables must have a type assigned
3A) target
4A) rootDir
5A) Skips checking the types of declaration files (.d.ts)
6B) classic
7A) "sourceMap": true
8A) outDir
9A) Allows default import of CommonJS modules
10A) "noEmit": true
11A) Use the --outFile compiler option
12A) --watch
13A) Generates declaration files (.d.ts) for TypeScript files
14A) "incremental": true
15A) "cleanUp": true
16A) Files to exclude from compilation
17A) --module
18A) "strict": true
19A) Removes comments from the output JavaScript files
20A) Use the rootDirs option
21A) To provide type information for JavaScript libraries
22D) Both A and C
23B) TypeScript will treat the libraries as any
24A) declare var globalVar: string;
25A) declare module 'module-name' { export type myType; }
26A) declare function myFunction(): void;
27A) declare interface MyInterface {}
28A) Yes, with the declare module keyword
29A) Makes the declared type or function available for import
30C) /// <reference path="file.d.ts" />

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top