Loading lessons...
tsconfig.json & Essential Compiler Options
tsconfig.json Configuration & Compiler Options
The tsconfig.json file specifies root files and compiler options required to compile a TypeScript project.
Creating a tsconfig.json
Generate a default configuration file using:
tsc --init
Essential Compiler Options
| Option | Recommended Setting | Purpose |
|---|---|---|
target | "ES2022" or "ESNext" | Target JavaScript language version emitted. |
module | "NodeNext" or "ESNext" | Module system specification for output code. |
strict | true | Enables all strict type-checking options. |
noImplicitAny | true | Raises error on expressions with implied any type. |
strictNullChecks | true | Ensures null and undefined are handled explicitly. |
outDir | "./dist" | Output directory for compiled .js files. |
rootDir | "./src" | Root directory of input TypeScript files. |
Sample tsconfig.json
{
"compilerOptions": {
"target": "ES2022",
"module": "commonjs",
"rootDir": "./src",
"outDir": "./dist",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src/**/*"]
}
TL;DR
- Run
tsc --initto generate a startertsconfig.json. - Always set
"strict": truefor maximum safety. - Use
outDirandrootDirto organize build inputs and outputs cleanly.