tsconfig.json is a configuration file for the TypeScript compiler (tsc) that tells it:
What files to include/exclude
Which version of JS to output
How strict the type checks should be
Module system to use, etc.
🧰 Sample tsconfig.json
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"outDir": "./dist",
"rootDir": "./src"
},
"include": ["src"],
"exclude": ["node_modules"]
}🔍 Key Fields Explained
📁 "include" and "exclude"
include: Files/folders to compileexclude: Files/folders to skip (defaults tonode_modules)
🛠️ "compilerOptions" – Most Important Properties
Option | Description |
|---|---|
| JS version to compile to (e.g., |
| Module system to use ( |
| Where to put compiled |
| Where your |
| Enable all strict type-checking options |
| Allow |
| Ensures consistent import case (important for cross-OS compatibility) |
| Skips checking |
✅ Strict Mode Options
If you want fine-grained control over type safety:
"strict": true...is shorthand for enabling all of these:
"strictNullChecks": true,
"noImplicitAny": true,
"strictBindCallApply": true,
"strictFunctionTypes": true,
"alwaysStrict": true,
"noImplicitThis": true,
"useUnknownInCatchVariables": true🧪 Useful Extras
Option | What It Does |
|---|---|
| Compile for type-checking only (don’t emit .js files) |
| Error for unused variables |
| Error for unused function parameters |
| Ensure all code paths return a value |
| Allows importing |
| Allows compiling |
| Type-check |
🔁 Inheritance with extends
You can create a base config and extend it:
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"outDir": "dist"
}
}Useful for mono-repos or large projects.
🧠 Tips
Use
tsc --initto generate a starter config.Use
tsc --showConfigto see final resolved config.Some settings (like
paths,baseUrl) are useful in frameworks like Next.js, NestJS, etc.