What is the purpose of the tsconfig.json file in a TypeScript project?
The tsconfig.json file tells the TypeScript compiler how to compile the project. It sets options like which files to include, where to put the output, and how strict the checks should be.
Click to reveal answer
beginner
What does the compilerOptions section in tsconfig.json do?
The compilerOptions section sets rules and settings for the TypeScript compiler, like the target JavaScript version, module system, and whether to allow certain language features.
Click to reveal answer
intermediate
What is the effect of setting "strict": true in tsconfig.json?
Setting "strict": true turns on all strict type-checking options. This helps catch more errors early by making TypeScript more careful about types.
Click to reveal answer
beginner
How do you specify which files TypeScript should compile using tsconfig.json?
You can use the include and exclude arrays to tell TypeScript which files or folders to compile or ignore.
Click to reveal answer
beginner
What does the outDir option do in tsconfig.json?
The outDir option tells TypeScript where to put the compiled JavaScript files after compiling.
Click to reveal answer
What is the default file name for the TypeScript configuration file?
Atsconfig.json
Btypescript.json
Cconfig.json
Dtsconfig.js
✗ Incorrect
The TypeScript compiler looks for a file named tsconfig.json by default.
Which compilerOptions setting controls the JavaScript version output?
Amodule
Btarget
CoutDir
Dstrict
✗ Incorrect
The target option sets the JavaScript version (like ES5, ES6) that TypeScript will output.
How do you exclude files from compilation in tsconfig.json?
AUsing the <code>skip</code> option
BUsing the <code>ignore</code> array
CUsing the <code>exclude</code> array
DUsing the <code>remove</code> option
✗ Incorrect
The exclude array lists files or folders that TypeScript should not compile.
What does setting "strict": true do?
AEnables all strict type checking options
BDisables all type checking
COnly checks for syntax errors
DAllows JavaScript files to be compiled
✗ Incorrect
Setting "strict": true enables all strict type checking features to catch more errors.
Where does the outDir option send compiled files?
ATo the root folder
BTo the <code>src</code> folder
CTo the <code>node_modules</code> folder
DTo the folder specified by <code>outDir</code>
✗ Incorrect
The outDir option specifies the folder where compiled JavaScript files are saved.
Explain the main purpose of the tsconfig.json file and name three common options you can set inside it.
Think about how TypeScript knows what to compile and how.
You got /4 concepts.
Describe what happens when you set "strict": true in your tsconfig.json and why it might be helpful.
Consider how strict type checking affects your code quality.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of the tsconfig.json file in a TypeScript project?
easy
A. To run the TypeScript compiler manually
B. To list all JavaScript files in the project
C. To install TypeScript packages
D. To configure how TypeScript compiles the project
Solution
Step 1: Understand the role of tsconfig.json
The tsconfig.json file tells TypeScript how to compile the project, including options and files.
Step 2: Compare options
The other options describe unrelated tasks: listing files, installing packages, or running commands manually.
Final Answer:
To configure how TypeScript compiles the project -> Option D
2. Which of the following is the correct way to specify the JavaScript version target in tsconfig.json?
easy
A. {
"target": "ES6"
}
B. {
"compilerOptions": {
"target": "ES6"
}
}
C. {
"compilerOptions": {
"version": "ES6"
}
}
D. {
"compilerOptions": {
"jsVersion": "ES6"
}
}
Solution
Step 1: Identify correct property for target
The correct property inside compilerOptions to set JavaScript version is target.
Step 2: Check JSON structure
The snippet with target nested inside compilerOptions is correct. The one with target directly at root misses the compilerOptions wrapper. The ones using version or jsVersion have wrong property names.
Final Answer:
{
"compilerOptions": {
"target": "ES6"
}
} -> Option B
Quick Check:
target inside compilerOptions = correct [OK]
Hint: Always put target inside compilerOptions [OK]
Common Mistakes:
Placing target outside compilerOptions
Using wrong property names like version or jsVersion
The exclude property must be an array of strings, but here it is a single string.
Step 2: Validate other properties
target with "ES6" is valid, outDir can be any folder name, and include is correctly an array.
Final Answer:
"exclude" should be an array, not a string -> Option C
Quick Check:
exclude must be array [OK]
Hint: exclude always needs brackets [] [OK]
Common Mistakes:
Using string instead of array for exclude
Thinking ES6 is invalid target
Confusing include and exclude types
5. You want to compile only TypeScript files inside the app folder but exclude test files ending with .spec.ts. Which tsconfig.json configuration achieves this?
hard
A. {
"include": ["app/**/*.ts"],
"exclude": ["**/*.spec.ts"]
}
B. {
"include": ["app/**/*.ts", "!app/**/*.spec.ts"]
}
C. {
"include": ["app/**/*.ts"],
"exclude": ["app/**/*.test.ts"]
}
D. {
"include": ["app/**/*.ts"],
"exclude": ["app/*.spec.ts"]
}
Solution
Step 1: Understand include and exclude patterns
To compile files in app, include app/**/*.ts. To exclude test files ending with .spec.ts, exclude **/*.spec.ts globally.
Step 2: Evaluate options
{
"include": ["app/**/*.ts"],
"exclude": ["app/*.spec.ts"]
} excludes only top-level test files directly in app, missing those in subfolders. {
"include": ["app/**/*.ts", "!app/**/*.spec.ts"]
} uses negation in include, which is invalid. {
"include": ["app/**/*.ts"],
"exclude": ["app/**/*.test.ts"]
} excludes .test.ts files, not .spec.ts.
Step 3: Choose best practice
{
"include": ["app/**/*.ts"],
"exclude": ["**/*.spec.ts"]
} correctly includes all .ts files in app and excludes all .spec.ts files anywhere, ensuring test files are excluded.
Final Answer:
Include app/**/*.ts and exclude **/*.spec.ts -> Option A
Quick Check:
exclude **/*.spec.ts filters test files [OK]
Hint: Use exclude with **/*.spec.ts to skip test files [OK]
Common Mistakes:
Using negation inside include array
Excluding wrong test file patterns
Not excluding test files at all
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.