What is tsconfig.json?
tsconfig.json is the configuration file for TypeScript projects. It defines compiler options, file inclusion/exclusion rules, and project settings. Without it, TypeScript uses default settings.
Basic tsconfig.json
Complete Compiler Options Reference
| Category | Option | Description | Recommended |
|---|---|---|---|
| Language | target | JS version output | ES2020+ |
| Language | lib | Runtime libraries | ES2020, DOM |
| Language | jsx | JSX support | react-jsx |
| Modules | module | Module system | ESNext/CommonJS |
| Modules | moduleResolution | Module resolution | bundler/node10 |
| Modules | resolveJsonModule | Import JSON | true |
| Output | outDir | Output directory | ./dist |
| Output | rootDir | Source root | ./src |
| Output | declaration | Generate .d.ts | true (libraries) |
| Output | sourceMap | Source maps | true |
| Strict | strict | All strict flags | true |
| Strict | noImplicitAny | Disallow any | true |
| Strict | strictNullChecks | Null safety | true |
| Interop | esModuleInterop | ES interop | true |
| Interop | allowSyntheticDefaultImports | Default imports | true |
| Performance | skipLibCheck | Skip .d.ts check | true |
| Performance | incremental | Incremental builds | true |
Preset Configurations by Project Type
Node.js Backend
React Frontend
Library (npm Package)
Path Mapping
Project References (Monorepo)
Type Checking Options
Extended Configurations
CLI Flags vs tsconfig.json
| Use Case | tsconfig.json | CLI Flag |
|---|---|---|
| Project-wide settings | ✅ Best | ❌ Cumbersome |
| One-off builds | ❌ Overkill | ✅ Quick |
| Team consistency | ✅ Required | ❌ Not shared |
| CI/CD pipelines | ✅ Best | ⚠️ Possible |
| Watch mode | ✅ tsc --watch | ✅ tsc --watch |
Debugging Configuration
Common Mistakes
- Forgetting to set rootDir – Causes unexpected output structure
- Using outDir instead of rootDir – Misunderstood paths
- Not using strict mode – Missing type safety benefits
- Including node_modules – Slow compilation
- Missing declaration files for libraries – No .d.ts output
- Inconsistent module resolution – Import errors
Best Practices
- Always enable strict mode – Catch more errors
- Use incremental builds – Faster compilation
- Extend base configs – DRY configuration
- Set correct target – Based on your environment
- Use project references – For monorepos
- Commit tsconfig.json – Share with team
- Validate config – Use tsc --showConfig
Conclusion
tsconfig.json is the heart of every TypeScript project. Understanding compiler options enables you to optimize builds, enforce coding standards, and configure TypeScript for any environment. Start with strict mode and customize based on your project needs.