TSConfig Cheat Sheet
•
typescript configuration reference
Base Configuration
Start with these essential options:
{
"compilerOptions": {
"esModuleInterop": true,
"skipLibCheck": true,
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "bundler",
"strict": true
}
}
Strictness Options
Enable all strict checks:
{
"compilerOptions": {
"strict": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true
}
}
Individual strict flags (enabled by strict: true):
noImplicitAny: Require types for all variablesstrictNullChecks: Enforce null/undefined handlingstrictFunctionTypes: Stricter function type checkingstrictBindCallApply: Type-check bind/call/applystrictPropertyInitialization: Require property initialization
Module Resolution
For Bundlers (Vite, Webpack, esbuild)
{
"compilerOptions": {
"moduleResolution": "bundler",
"module": "ESNext",
"allowImportingTsExtensions": true,
"noEmit": true
}
}
For Node.js (CommonJS)
{
"compilerOptions": {
"module": "CommonJS",
"moduleResolution": "node"
}
}
For Node.js (ESM)
{
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "NodeNext"
}
}
Library Building
Publishing a package:
{
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"outDir": "./dist"
}
}
DOM Projects (Frontend)
{
"compilerOptions": {
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"jsx": "react-jsx"
}
}
Monorepo Configuration
Base tsconfig.json:
{
"compilerOptions": {
"composite": true,
"declaration": true,
"declarationMap": true
}
}
Reference other packages:
{
"extends": "../../tsconfig.base.json",
"references": [
{ "path": "../shared" }
]
}
Path Aliases
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"],
"@components/*": ["./src/components/*"]
}
}
}
Recommended Complete Config
{
"compilerOptions": {
// Language
"target": "ES2022",
"lib": ["ES2022"],
// Modules
"module": "ESNext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
// Emit
"declaration": true,
"sourceMap": true,
"outDir": "./dist",
// Interop
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
// Type Checking
"strict": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,
// Skip checking node_modules
"skipLibCheck": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}