The Broad Way

[ Sharp Mind · Sharp Blade · Sharp Spirit ]

root@construct:~
/typescript-strict-mode-changed-how-i-think
$_
<-- back to /logs
2026-01-07//LOG

TypeScript Strict Mode Changed How I Think

I turned on strict mode in a legacy NestJS codebase last week. 847 errors. EIGHT HUNDRED AND FORTY SEVEN. I stared at my terminal for a solid minute before closing the laptop and going to make coffee. But here is the thing. Every single one of those errors was a real problem. Not a theoretical "well maybe this could be null" situation. Actual, production-ready bugs hiding behind loose types. The worst offenders were the ones you expect. Optional properties being accessed without checks. Functions returning undefined when the caller assumes a value. Objects typed as any being passed through three layers of abstraction until nobody knows what shape they are anymore. Classic. Enabling strictNullChecks alone surfaced about 200 issues. Every one of them was a potential runtime crash waiting for the right (wrong) input. The kind of bugs that show up at 2 AM on a Saturday when some edge case user submits a form with an empty string where you expected a number. strictPropertyInitialization caught another batch. Classes with properties that were "definitely assigned in the constructor" except they WERE NOT. They were assigned in some init method that gets called after construction, maybe, if the stars align. Here is what changed in how I think: I stopped treating types as documentation and started treating them as contracts. When I write a function signature now, I think about what happens when the input is null. When I define an interface, I think about which fields are truly optional versus which ones I was just too lazy to make required. The migration took three days. Three painful, tedious, soul-crushing days of adding null checks and fixing type assertions. But since then? Zero type-related bugs in production. ZERO. The compiler catches them all at build time. My advice: enable strict mode on day one of every project. If you are inheriting a codebase without it, carve out a week and just do it. Yes it will hurt. Yes you will question your career choices. But the alternative is finding those bugs in production, and that hurts MORE. Strict TypeScript is not a style preference. It is a quality gate. Treat it like one.
The Broad Way | Kinho.dev