tsconfig Basics
TypeScript · Reference cheat sheet
tsconfig Basics
TypeScript · Reference cheat sheet
📋 Overview
tsconfig.json tells the TypeScript compiler how to check and emit your project. One config at the repo root (or package root) is the usual starting point.
🔧 Core concepts
| Option area | Examples | Role |
|---|---|---|
compilerOptions | strict, target, module | How to check/emit |
include / exclude | ["src"] | Which files belong |
files | Rare | Explicit file list |
extends | "@tsconfig/node20" | Share base configs |
| Project references | Advanced | Multi-package monorepos |
Turn on strict: true early — it enables a bundle of safer checks.
💡 Examples
Beginner-friendly Node config:
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"outDir": "dist",
"rootDir": "src"
},
"include": ["src"]
}Create a starter config via CLI:
npx tsc --initCheck without emitting JS:
npx tsc --noEmitBrowser / bundler-oriented snippet:
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "Bundler",
"jsx": "react-jsx",
"strict": true,
"noEmit": true
},
"include": ["src"]
}⚠️ Pitfalls
- Wrong
rootDir/includepulls innode_modulesor test junk. targettoo old or too new can confuse beginners — ES2020+ is a solid default.- Mixing
"module": "CommonJS"with ESMimportneeds care. - Editing
tsconfigwithout restarting the editor language service can show stale errors.