TypeScript Strict Mode Configuration
Intermediatev1.0.0
Configure TypeScript for maximum type safety — strict mode flags, essential tsconfig.json settings, path aliases, and project references for monorepos.
Content
Overview
A properly configured tsconfig.json is the foundation of type-safe TypeScript. Strict mode catches entire categories of bugs at compile time. This skill covers the essential settings every project needs.
Why This Matters
- -Bug prevention — strict mode catches ~40% more errors than default config
- -Null safety — strictNullChecks prevents the "billion dollar mistake"
- -Consistency — team-wide settings prevent configuration drift
- -IDE support — proper config enables full autocomplete and refactoring
The Essential tsconfig.json
What strict: true Enables
| Flag | What It Does |
|---|---|
| `strictNullChecks` | null/undefined are distinct types — must handle explicitly |
| `noImplicitAny` | Variables must have types — no implicit any |
| `strictFunctionTypes` | Function parameter types checked contravariantly |
| `strictBindCallApply` | bind/call/apply check argument types |
| `strictPropertyInitialization` | Class properties must be initialized |
| `noImplicitThis` | this must have an explicit type |
| `alwaysStrict` | Emit "use strict" in output |
| `useUnknownInCatchVariables` | catch variables are unknown, not any |
Additional Recommended Flags
Path Aliases with @
Best Practices
- -Start with
strict: trueon new projects — non-negotiable - -Add
noUncheckedIndexedAccessfor safer array/object access - -Use path aliases to avoid deep relative imports
- -Keep
skipLibCheck: truefor faster compilation - -Set
isolatedModules: truefor compatibility with esbuild/SWC/Vite
Common Mistakes
- -Starting without strict mode and trying to add it later (painful)
- -Using
anyto fix strict mode errors instead of proper types - -Not matching module/moduleResolution to your runtime (Node16 for Node.js)
- -Forgetting to configure path aliases in bundler/test runner too
FAQ
Discussion
Loading comments...