Is "turn on strict" one decision or eight?
Every migration guide says the same thing: set "strict": true and fix what breaks. It reads like one switch. It's eight, they don't cost the same, and nobody publishes the price list.
So I priced one. Not a toy, and not a repo that was already halfway there. I wanted a public TypeScript project with a tsconfig.json that names no strict flag at all, a size where a human could plausibly do the work, and a clean tsc run to start from. I tried a handful of well-known repos and most had already flipped the switch. redis/ioredis hadn't: 61 files under lib/, 19,995 lines counted with wc -l (comments and blanks included), TypeScript 5.4.5 from its lockfile, commit 81bc16a, and a baseline of exactly 0 errors.
Environment, since a number without one is decoration: macOS, Node 22.23.3, tsc --noEmit for every count. I didn't time any human effort, so there's no person-hours figure here. What follows is what the compiler said, and what my diff looked like.
What does each flag cost on its own?
I ran tsc --noEmit once per flag, each alone, against the untouched commit.
| Flag | Errors | Files |
|---|---|---|
| strictNullChecks | 197 | 17 |
| noImplicitAny | 133 | 16 |
| noImplicitThis | 48 | 5 |
| strictPropertyInitialization | 36 (on top of strictNullChecks) | 6 |
| strictBindCallApply | 3 | 3 |
| useUnknownInCatchVariables | 2 | 2 |
| strictFunctionTypes | 1 | 1 |
| alwaysStrict | 0 | 0 |
All together (--strict) |
405 | 26 |
Two things in that table surprised me.
First, strictPropertyInitialization can't be measured alone. Run it by itself and tsc answers TS5052: Option 'strictPropertyInitialization' cannot be specified without specifying option 'strictNullChecks'. That "1" you'd get from a naive loop is a config error, not a finding. I counted it as the difference between strictNullChecks plus strictPropertyInitialization (233) and strictNullChecks alone (197): 36, of which 21 are the classic TS2564 "has no initializer" on class fields.
Second, the parts don't add up to the whole. The rows sum to 420; --strict reports 405. My read is that one expression can trip two flags and tsc reports it once, so the overlap eats errors. The reverse happens too. strictFunctionTypes plus strictBindCallApply gave 5 errors where the two flags alone gave 1 and 3, because an apply call in lib/utils/debug.ts only became an error once both were on. So don't budget by adding up a table like mine. Budget by running the combination you intend to ship.
Where do the errors pile up?
Not evenly. Four files hold 261 of the 405 errors, 64 percent: Pipeline.ts with 81, DataHandler.ts with 73, cluster/index.ts with 54, Redis.ts with 53. Twenty-two other files share the remaining 144, and 35 of the 61 files produce nothing at all.
That shape matters more than the total. A flat 405 means a long, dull slog everywhere. This shape means most of the codebase is already effectively strict and the debt lives in the hardest, most dynamic code: the pipeline builder, the socket data handler, the cluster client. Those are also the files where a wrong type is most likely to hide a real bug, which is the awkward part. The errors you most want to see are the ones that cost the most to fix.
What's inside the two big flags is less exotic than I expected. Under noImplicitAny, 56 of 133 are TS7053 (indexing an object with a plain string) and 51 are TS7006 (a parameter with no type). Under strictNullChecks, the largest groups are TS2322 and TS2345 (a possibly-null value assigned or passed where a definite one is expected) at 43 and 38, then 56 combined TS18047/TS18048 ("possibly null" and "possibly undefined"). None of that needs cleverness. It needs a decision per site: is this value really optional, or did the code just never say?
What did the cheap flags actually cost?
I made a scratch branch and fixed the five cheapest flags: alwaysStrict, strictFunctionTypes, strictBindCallApply, useUnknownInCatchVariables and noImplicitThis. They account for 54 errors alone. After the pass, all five are enabled in tsconfig.json and tsc --noEmit reports 0.
| What | Count |
|---|---|
Files changed (including tsconfig.json) |
10 |
| Lines added / removed | 38 / 26 |
| Errors removed | 54 |
New @ts-expect-error |
0 |
New this: any annotations |
7 |
New type casts (as Error, as Parameters<...> and similar) |
6 |
That's 64 changed lines in a 19,995-line codebase, 0.3 percent. I'm saying so plainly because the count of lines is the number people argue about, and it's small. The count of compromises is the one worth reading, and it isn't zero.
The seven this: any are the honest cost of noImplicitThis. ioredis builds a lot of its API by assigning functions onto prototypes (Pipeline.prototype.exec = function () { ... }). With the flag on, tsc gives this the contextual type Pipeline, and that exposed 30 real errors in Pipeline.ts alone: private fields touched from outside the class, a redis member typed as Cluster | Redis where the code assumed the cluster side. Fixing those properly is a refactor of how the class is assembled. I wasn't going to smuggle a refactor into a flag flip, so I wrote this: any seven times. The flag is on, the errors are gone, and I haven't proven anything about those functions. I'd rather you hear that from me than discover it.
The six casts are small lies. useUnknownInCatchVariables turns err in a catch block from any into unknown. Two spots passed it straight to something typed Error, and I wrote err as Error. If a non-Error is ever thrown there, the type is wrong and nothing says so. The proper fix is a runtime check, which changes behavior, and I can't tell you whether that matters to ioredis users.
One fix changed a decision. this.emit.apply(this, arguments) in silentEmit failed strictBindCallApply because arguments isn't a tuple. The tidy rewrite is this.emit(eventName, arg). It type-checks and it isn't the same: it always passes two arguments, where the original forwarded however many the caller supplied. I kept the original semantics with a cast instead. A type error and its cleanest-looking fix can disagree about what the code does.
What I did not do: run ioredis's runtime tests. They need a live Redis server, and I had none on the machine (Docker's daemon wasn't running either). What I did run: tsc clean under the five flags, and the project's tsd typings test, which passed. That tells you the published typings still check. It doesn't tell you the changed runtime code (the hostname lookup in the cluster client, a setImmediate callback, the emit call) behaves identically. The patch is in the example folder, so the first thing to do with it is run their suite.
What does a ratchet look like?
Three flags are left: 133, 198 and 36 errors alone, and 346 together under --strict after my pass. You can't land that as one pull request without stopping the world, and you shouldn't try. The alternative that actually survives is a ratchet: let the debt exist, forbid it from growing.
I wrote one in under sixty lines of Node with no dependencies. It runs tsc once per outstanding flag, parses the file(line,col): error TS... lines, and stores the error count per flag, per file. Per file matters. A total can be gamed: fix three errors in Redis.ts, add three in Pipeline.ts, and the number hasn't moved. A per-file count means each file may only stay level or improve, and because it counts errors rather than recording line numbers, editing the top of a file doesn't invalidate anything.
First run writes the baseline. Second run with no changes passes. Then I pasted a four-line sloppy function into lib/utils/index.ts, an untyped parameter and an unchecked string | undefined, and ran it again:
REGRESSION noImplicitAny: lib/utils/index.ts went 2 -> 3
REGRESSION strictNullChecks: lib/utils/index.ts went 1 -> 2
2 new strict-mode error(s). Fix them; do not raise the baseline.
exit 1
That's the whole mechanism. The --update flag rewrites the baseline, but only when nothing regressed, so it can tighten the number and never loosen it. Cost: three tsc passes took 6.6 seconds wall time on this repo, against 2.5 seconds for a single --strict run. Cheap enough to run on every pull request. Where tsc takes minutes, you'd run it per flag in parallel jobs instead.
Wire it as two tiers. The flags you've already paid for go in tsconfig.json, where a single error fails tsc --noEmit. The flags you haven't go through the ratchet, where errors may only shrink. When a flag hits zero, move it into the tsconfig and delete it from the ratchet's list. If that sounds like the suppression problem wearing a different hat, it's related, but there's one difference I care about: the ratchet makes the debt countable and one-directional. A pile of @ts-expect-error comments does neither.
One caveat I haven't tested: renaming a file resets its entry to zero allowed, so a rename of a file with debt would fail the check until the baseline is updated. I'd expect that, and I'd treat it as a feature, but I haven't run it.
Does the default change who pays?
This repo's tsconfig.json was already out of date for a newer reason. TypeScript 7.0.2 is now the latest tag on npm, so I ran it against the same commit as a cross-check. It wouldn't load the old config as written: it rejected moduleResolution: node outright, and Buffer and BufferEncoding went missing until I listed @types/node explicitly. I removed the first line and added "types": ["node"], and those two edits were the only config changes.
Then the interesting part. With no strict key at all, 7.0.2 reported 414 errors, identical to passing --strict. With --strict false it reported 9, and those 9 are unrelated to strictness. Take the 9 away and the per-flag numbers land on top of the 5.4.5 results: strictNullChecks 197, noImplicitThis 48, strictBindCallApply 3, useUnknownInCatchVariables 2, strictFunctionTypes 1, alwaysStrict 0, and noImplicitAny 134 against 133. Same errors, different compiler.
So the question "should we turn strict on?" is turning into "should we opt out?" for anyone who upgrades. A team that stays on an old tsconfig and bumps the compiler doesn't skip this bill. It receives the bill on the day of the upgrade, with no ratchet in place.
What would I do on a repo this size?
My position, and you're free to disagree: land the cheap flags in one pull request and split the null checks. The cheap pass here was 54 errors in 10 files, and it turns on enforcement for everything written afterwards. The null-check pass is 198 decisions across 17 files, and a pull request that size gets approved by fatigue, not by review.
Three habits keep the bill bounded:
- Measure each flag alone, then the combination, and expect the sum to be wrong in both directions.
- Write down every compromise in the diff. Mine was seven
this: anyand six casts. A flag flipped on top of silentanyis the gameable type check I described in my twelve CI gates. - Ratchet per file, not per total, and only let the baseline move down.
This is also why a typed lint rule can't stand in for the compiler. I hit the same wall in the linter comparison: rules that need type information report noise until tsconfig agrees about strictness.
What I didn't measure, so you don't have to guess: human time, whether the changed runtime code behaves identically under a real Redis, and any Python equivalent. I considered a second pass with mypy --strict on a small Python repo and dropped it. It wouldn't have added a number I could stand behind, and a thin comparison is worse than none. The scripts, the patch and the ratchet are in blogs/zero-bugs/examples/turning-on-typescript-strict-on-an-existing-project-what-it-cost/, so check my counts against your own repo before you trust mine.