WEB DEVELOPMENT · 21 MAY 2023 · READ TIME: 9 MIN
Why TypeScript strict mode is worth the initial pain
Enabling TypeScript's strict mode on an existing codebase that wasn't built with it typically surfaces dozens or hundreds of type errors immediately, implicit `any` types, possibly-null values accessed without a check, function parameters that were never actually type-safe, and that wall of errors is exactly the reason teams delay turning it on, even though it's also exactly the reason to turn it on.
Every one of those surfaced errors represents a genuine, pre-existing gap in the code's type safety that strict mode didn't create, it just made visible, and a codebase running without strict mode isn't actually safer than one that's been through this correction, it's just deferring the discovery of the same bugs to whenever they happen to manifest at runtime instead of at compile time.
The practical path that avoids a multi-week blocking cleanup: enable strict mode for new files immediately, and either budget dedicated time to work through the existing errors incrementally, file by file, or use TypeScript's ability to suppress strict checking on specific legacy files while still enforcing it everywhere new code gets written.
The pain of turning on strict mode is real and front-loaded. The alternative isn't a codebase without those bugs, it's a codebase with the same bugs, still there, just undiscovered until a user hits one in production instead of a compiler catching it before the code ever ships.
Nikunj Chugh
Growth systems architect: AI automation, media buying, web & SEO.