TypeScript Configuration
The One Flag That Found 200 Bugs
{
"compilerOptions": {
"strict": true
}
}// Before strict mode - compiled fine
function getUserName(user) { // Implicit any
return user.name.toUpperCase(); // Crashes if user is null!
}
// Error found by strict mode:
// ✗ Parameter 'user' implicitly has an 'any' typeBasic tsconfig.json
Bare Minimum
What Each Option Does
Strict Mode Options
strict: true (Recommended)
Individual Strict Options
noImplicitAny
Without noImplicitAny (Dangerous)
With noImplicitAny
strictNullChecks
Without strictNullChecks
With strictNullChecks
strictPropertyInitialization
Without strictPropertyInitialization
With strictPropertyInitialization
Module Options
module and moduleResolution
esModuleInterop
Target and Lib
target
lib
Path Configuration
baseUrl and paths
Source Maps
sourceMap
inlineSourceMap
Declaration Files
declaration
Additional Checks
noUnusedLocals and noUnusedParameters
noImplicitReturns
noFallthroughCasesInSwitch
Project References
Basic Setup
Real-World Configs
Node.js Server
React App
NPM Library
Common Mistakes I Made
1. Not Enabling Strict Mode
2. Wrong Target for Environment
3. Including Test Files in Build
Your Challenge
Key Takeaways
What I Learned
Last updated