Repository navigation
Write runtime lib, state, transport and base in TypeScript - #7429
Conversation
Converts 86 modules from JSDoc-typed JavaScript to TypeScript, mechanically: JSDoc parameter, return, template, overload, typedef, import and cast annotations became TypeScript syntax; inline import() types became type imports. Each module's compiled .js parses to the same program as the JavaScript it replaces, apart from RequestError, which now declares its four fields. The runtime/lib modules the Effect UI port is reworking (leaf-element, controls, widget-events, failure, pending-task, time-axis, icons, frame-pass) stay JavaScript for now, as does the generated syntax-languages.js. - knip takes each TypeScript module as an entry, so the types only it uses count as used. - The keydown-listener register test counts base/field-keys.js, whose listener a cast had hidden from the parse: it stops a field's keys after its readers see them, and answers none. - The package references say a TypeScript library module keeps its types in the .ts beside the .js a widget imports. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01V22NWabEKzt7s5HiW4koa7
leaf-agent
left a comment
There was a problem hiding this comment.
The test job is red because of this change: check:worker (tsc --noEmit --project worker/tsconfig.json) fails with 97 errors in browser/runtime/lib/shadow-tree.ts and browser/runtime/state/widget-imports.ts (run). I reproduced it locally at this head.
worker/test/runtime-preloads.test.ts imports ../../browser/runtime/state/widget-imports.js. Under moduleResolution: "Bundler", TypeScript resolves that import to the new sibling widget-imports.ts, and from there to shadow-tree.ts. Before this PR it read only the .js, which allowJs without checkJs never type-checked. The Worker's project has lib: ["ESNext"] and no DOM, so Node, Document, ShadowRoot and the rest are undefined there.
Adding "DOM" to the Worker's lib doesn't fix it. That clashes with @cloudflare/workers-types (Request/BodyInit errors in worker/src/index.ts and worker/test/index.test.ts), and happy-dom's HTMLElement still isn't assignable to Scope at runtime-preloads.test.ts lines 35–36. One way that does type-check: exclude runtime-preloads.test.ts from worker/tsconfig.json and check it in a small project with lib: ["ESNext", "DOM", "DOM.Iterable"], casting the happy-dom element to Element at the two call sites. I tried that config, and with the cast it's clean.
The same thing will happen whenever a module the Worker imports gets a .ts beside it, so where the Worker type-checks browser code is worth settling once rather than case by case. worker/bundle-runtime.mjs also imports widget-imports.js, but it's outside the project's include.
The Worker's build (bundle-runtime.mjs) imports the browser runtime's widget-imports, which now resolves to its TypeScript source. That module is written for the DOM, which the Worker's own project leaves out because its types clash with the Workers runtime's. The two tests of the build run in Node, so they now type-check in worker/tsconfig.node.json, with the DOM and Node's types, and check:worker runs both projects. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01V22NWabEKzt7s5HiW4koa7
leaf-agent
left a comment
There was a problem hiding this comment.
The branch now conflicts with main in browser/runtime/base/document-inputs.js, since #7426 changed that module (it keeps a user's chosen <select> options across reloads). GitHub runs no PR CI on a conflicting head, so nothing has checked this head. When you rebase, carry #7426's change into document-inputs.ts and rebuild the .js from it. Resolving only the .js conflict would leave the .ts source without the change, and the next build would drop it.
The Worker type-check fix resolves the earlier finding: tsc over worker/tsconfig.json and worker/tsconfig.node.json both pass at this head, and test:worker passes.
…-aoeudz # Conflicts: # browser/runtime/base/document-inputs.js
A merge can bring a change to a compiled .js from a branch that predates its .ts. The output check called it stale and asked for a rebuild, which would drop the change. It now names each such module apart from stale output and asks for the change to move into the .ts first, and build/AGENTS.md says the same. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01V22NWabEKzt7s5HiW4koa7
…7433) <!-- claude-projects-attribution: {"github_login":"max-sixty"} --> _Requested by **Maximilian** · [project thread](https://claude.ai/code/project/chan_01HAT2svakg1fTA5kitqhX9w?thread=cmsg_01HAT2svakg1fTA5kitqhX9wERfAJinBvZtiP4jvQpWkPy)_ Converts the rest of the runtime that the Effect UI port doesn't hold to TypeScript, following #7429: - dom, readings, records, features, host and annotations - the top-level modules age, bootstrap, check-api, prepaint, stage-integration, validation and widget-api These stay JavaScript: - the port's modules: `dom/box-motion`, `dom/css-anchors`, `annotations/annotation-overlay/`, `effect-widget`, `widget-services` and `portable-api` - `annotations/preview.js`, until the port's #7417 lands **What runs doesn't change.** With comments ignored, each compiled `.js` parses to the same program as the JavaScript it replaces on main, apart from two modules: - `records/thread/address.js`: `claim` is now an arrow, which carries the type a JSDoc `@type` gave the function. Nothing calls it before its definition. - `host/state-application.js`: the copy-on-write of the authored and descriptor maps goes through one `writable` helper. It copies on a reading's first write to a map, as before. Other changes: - A class declares each field it assigns as `declare x: T`, with the type TypeScript inferred from the JavaScript. The strip erases these declarations. - A type is exported only where another module imports it, in this batch and in #7429's modules. - The `.ts` files carry #7426's changes to `bootstrap`, `prepaint`, `records/carry` and `host/application`, merged in at the TypeScript level. Checks run: - `tsc` over `browser/types/tsconfig.json` and both Worker projects - `check:browser`, `test:runtime` (1199 pass), `test:browser`, `test:worker` - `tests/model`: all pass except the bound-file permission test, which fails when the suite runs as root - every pre-commit hook on the changed files An independent review of the conversion found no behaviour change, and its type-level and doc-comment findings are fixed here. --- _Generated by [Claude Code](https://claude.ai/code)_ Co-authored-by: Claude <[email protected]>
Requested by Maximilian · project thread
Converts 86 runtime modules to TypeScript on the infrastructure from #7424: all of
runtime/state,runtime/transportandruntime/base, andruntime/libapart from the eight modules the Effect UI port is reworking (leaf-element, controls, widget-events, failure, pending-task, time-axis, icons, frame-pass) and the generatedsyntax-languages.js.Each
.tssits beside the.jsthe layer serves, whichbuild/typescript.mjscompiles from it. JSDoc types became TypeScript types,@typedefs becametypedeclarations (exported only where another file names them), casts becameas, and inlineimport("…")types becameimport type.What runs doesn't change. Parsed without comments, every compiled
.jsis the same program as the JavaScript it replaces, excepttransport/layer-client.js:RequestErrornow declares its four fields, which its constructor already assigned.Other changes:
.tsuses count as used. A side effect: knip doesn't report an exported type in a.tsthat nothing imports. Value exports are still checked through the compiled.js.base/field-keys.js, whose listener a JSDoc cast had hidden from the parse.worker/tsconfig.node.json, with the DOM's and Node's types: the build importsstate/widget-imports, whose TypeScript is written for the DOM, and the DOM's types clash with the Workers runtime's inworker/tsconfig.json.check:workerruns both.check:browsernames a compiled.jsthat differs from what its.tscompiles to apart from stale output, and asks for the change to move into the.tsfirst: a merge from a branch that predates the.tscan bring one, and a plain rebuild would drop it.build/AGENTS.mdsays the same. Merging main carried Keep the options a user chose in a select across reloads and revisions #7426'sdocument-inputschange into the.tsthis way..tsbeside the.jsa widget imports.Checks:
tscoverbrowser/types/tsconfig.jsonand both Worker projects,check:browser,test:worker,test:runtime(1197 pass) and every pre-commit hook on the changed files.https://claude.ai/code/session_01V22NWabEKzt7s5HiW4koa7
Generated by Claude Code