Repository navigation
Make strict the only type check (TS21) - #32
Merged
Merged
Conversation
tsconfig.base.json now sets strict, noUncheckedIndexedAccess and exactOptionalPropertyTypes, and allowJs only for site.config.js (checked through its own // @ts-check). The three loose programs and the four strict lists become five strict programs split by globals: worker (server/), web (src/), node, node-dom and node-all. port-check --strict-list keeps every TypeScript file in one of them, with no exclusions left; test:unit reads tests/*.test.ts.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TS21, the last PR of the strict TypeScript port. Strict is now the only type check: the three loose programs are gone, and every TypeScript file is in a strict program. Nothing changes at runtime: the build diff against main finds only three comment-only differences (below), and every JavaScript bundle is identical.
What changes for contributors
tsconfig.base.jsonsetsstrict,noUncheckedIndexedAccessandexactOptionalPropertyTypes(plusnoEmit) for every program.checkJsis gone.allowJsstays only so thatsite.config.js, the one JavaScript file in any program, is checked through its own// @ts-check.rg "checkJs|allowJs" tsconfig*.jsonshows just that line.bun run typecheckruns tsc on five strict programs, thenport-check --strict-list:tsconfig.worker.jsonserver/**/*.tstsconfig.web.jsonsrc/**/*.ts,types/dom.tstsconfig.node.jsonvite.config.ts,cloudflare.config.ts, unit tests of Worker modules and their helperstsconfig.node-dom.jsontsconfig.node-all.jsonserver/andsrc/useinclude, so a new file there is checked as soon as it exists. The Node programs list each file.server/is now checked strictly with Workers types only. Before this PR, it was checked strictly only with Node types mixed in.Retired:
tsconfig.strict.json,tsconfig.strict-web.json,tsconfig.strict-tests.json,tsconfig.strict-tests-shared.jsonandtypes/browser.d.ts. They were moved to the Recycle Bin and staged withgit add -u.test:unitreadstests/*.test.ts. No.mjstests were left, so the narrower glob drops none (371 unit tests on this branch).Why five programs, not three
The plan aimed for three. I tested each merge with the repo's tsc 7.0.2, and none of them type-checks cleanly:
@cloudflare/workers-typesdeclaresdeclare const Buffer: any, which hides Buffer's methods inscripts/lib/png-io.ts,scripts/lib/zip-read.ts,scripts/build-characters.tsandscripts/og-image.ts.scripts/live-chat-e2e.tsgetsunknownfromjson().BufferSourceandKeyUsageinserver/eventsub.tsandserver/backups.ts.live-chat-e2e.tsand onsrc/served/overlay.tsunder Workers types.scripts/devtools.tsandscripts/release.tsneed the genericjson<T>()from the Workers types.typesarray makes no difference.So the split follows the globals each file actually runs with.
port-check
STRICT_CONFIGand its three siblings become oneSTRICT_CONFIGStuple of the five configs.STRICT_EXCLUSIONSis gone, because every TypeScript file is now in a strict program.--strict-listprintstsconfig.worker.json, tsconfig.web.json, tsconfig.node.json, tsconfig.node-dom.json and tsconfig.node-all.json cover every TypeScript file.tests/port/port-check.test.tsuse the new names, and the five-list test covers all five.bun run test:port: 101/101 pass.port-renamenames the Node configs.Proof it changes no runtime code
node scripts/port-check.ts --base origin/main: 157 build output files compared, 3 different. All three are comment edits from the shipped-comments commit (assets/_headers,assets/admin/index.html,assets/dashboard.css), and every JS bundle is identical.package.json, port-check and its tests;types/browser.d.tsbeing gone;worker,webandnodeconfigs gaining the strict options.bun run checkpasses, with 371 unit tests.server/dedupe.tsfailedbun run typecheckwithTS7006intsconfig.worker.json. One added tosrc/scrub.tsfailed withTS7006intsconfig.web.json. Both were reverted and never committed.Docs and comments
docs/DEVELOPMENT.mdanddocs/CONTRACTS.md§9 describe the five programs, the new--strict-listmessage and thetest:unitglob.AGENTS.mdis 8168 bytes, down from 8179..coderabbit.yamlno longer namestsconfig.strict.json,eventsub.jsor.mjstests.public/_headers(includingvite.config.tson line 8),public/dashboard.cssandadmin/index.htmlname the.tssources. This is a separate commit, because these files ship.Left alone, on purpose
src/served/upload.ts:3(src/admin.js) andsrc/served/cosmetics.ts:2(tests/channel.test.mjs). All served modules share one?v=hash (servedVersioninscripts/lib/served.ts), so a comment edit there makes every open overlay reload once. They belong in a change that touches the overlay anyway.src/parse.tsSpecas{ [K in keyof T]-?: Check }. Two call sites stop compiling:STATE_CONFIGwould need retyping.LogRow.contexthas no check. Adding one changes the page bundle.NON_SHIPPINGinscripts/port-check.tsstill matchesvite\.config\.js$. Fixing it changes port-check's behavior, so it needs its own change.