0
0
Typescriptprogramming~20 mins

tsconfig.json Configuration Basics in Typescript - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
tsconfig.json Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this TypeScript compilation command?
Given this tsconfig.json file, what will be the output when running tsc in the same directory?
Typescript
{
  "compilerOptions": {
    "target": "ES5",
    "module": "commonjs",
    "outDir": "dist"
  },
  "include": ["src/**/*"]
}
ATypeScript files in the src folder are compiled to ES5 JavaScript and saved in the dist folder with CommonJS modules.
BCompilation fails because outDir must be inside src folder.
CTypeScript files are compiled to ES6 JavaScript and saved in the src folder with ES modules.
DTypeScript files are compiled but output is saved in the root directory.
Attempts:
2 left
💡 Hint
Check the meaning of target, module, and outDir in compilerOptions.
Predict Output
intermediate
2:00remaining
What error does this tsconfig.json cause?
Consider this tsconfig.json snippet. What error will the TypeScript compiler show?
Typescript
{
  "compilerOptions": {
    "target": "ES6",
    "module": "amd",
    "strict": true
  },
  "exclude": ["node_modules"]
}
AError: 'exclude' cannot be used with 'include'.
BError: 'strict' is not a valid compiler option.
CNo error; compilation succeeds with ES6 target and AMD modules.
DError: 'module' option 'amd' is not supported with target ES6.
Attempts:
2 left
💡 Hint
Check if 'strict' is a valid option and if AMD modules work with ES6 target.
🔧 Debug
advanced
2:00remaining
Why does this tsconfig.json cause a runtime error?
This tsconfig.json compiles without errors, but the output JavaScript throws an error at runtime. Why?
Typescript
{
  "compilerOptions": {
    "target": "ES5",
    "module": "ESNext",
    "lib": ["DOM", "ES2015"],
    "outDir": "build"
  },
  "include": ["app/**/*"]
}
AThe 'include' pattern is incorrect, so no files are compiled.
BThe 'lib' option is missing 'DOM', causing missing browser APIs at runtime.
CThe 'outDir' folder 'build' does not exist, causing runtime errors.
DUsing ESNext modules with ES5 target causes incompatible module syntax in output, leading to runtime errors.
Attempts:
2 left
💡 Hint
Think about how module syntax and target version affect the output JavaScript.
📝 Syntax
advanced
2:00remaining
Which tsconfig.json option is invalid here?
Identify the invalid option in this tsconfig.json:
Typescript
{
  "compilerOptions": {
    "target": "ES2020",
    "module": "commonjs",
    "allowJs": true,
    "outFile": "dist/app.js",
    "rootDir": "src",
    "noEmitOnError": false
  }
}
A"outFile" cannot be used with "module": "commonjs".
B"allowJs" must be false when "target" is ES2020.
C"rootDir" must be inside "outFile" directory.
D"noEmitOnError" must be true to emit files.
Attempts:
2 left
💡 Hint
Check compatibility between 'outFile' and 'module' options.
🚀 Application
expert
2:00remaining
How many files will be compiled with this tsconfig.json?
Given this tsconfig.json and the project structure below, how many TypeScript files will be compiled?
Typescript
{
  "compilerOptions": {
    "target": "ES6",
    "module": "commonjs"
  },
  "include": ["src/**/*.ts", "tests/**/*.ts"],
  "exclude": ["src/legacy/**"]
}

Project structure:
- src/app.ts
- src/utils.ts
- src/legacy/old.ts
- tests/test1.ts
- tests/helpers/test2.ts
- README.md
A5 files
B4 files
C3 files
D6 files
Attempts:
2 left
💡 Hint
Count files matching include patterns but not excluded.