Skip to content

Write runtime lib, state, transport and base in TypeScript - #7429

Merged
max-sixty merged 4 commits into
mainfrom
claude/project-thread-aoeudz
Nov 27, 2026
Merged

max-sixty merged 4 commits into
mainfrom
claude/project-thread-aoeudz

Conversation

@max-sixty

@max-sixty max-sixty commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

Requested by Maximilian · project thread

Converts 86 runtime modules to TypeScript on the infrastructure from #7424: all of runtime/state, runtime/transport and runtime/base, and runtime/lib apart 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 generated syntax-languages.js.

Each .ts sits beside the .js the layer serves, which build/typescript.mjs compiles from it. JSDoc types became TypeScript types, @typedefs became type declarations (exported only where another file names them), casts became as, and inline import("…") types became import type.

What runs doesn't change. Parsed without comments, every compiled .js is the same program as the JavaScript it replaces, except transport/layer-client.js: RequestError now declares its four fields, which its constructor already assigned.

Other changes:

  • knip takes each TypeScript module as an entry, so the types only a .ts uses count as used. A side effect: knip doesn't report an exported type in a .ts that nothing imports. Value exports are still checked through the compiled .js.
  • The keydown-listener register test now counts base/field-keys.js, whose listener a JSDoc cast had hidden from the parse.
  • The Worker build's two tests type-check in a project of their own, worker/tsconfig.node.json, with the DOM's and Node's types: the build imports state/widget-imports, whose TypeScript is written for the DOM, and the DOM's types clash with the Workers runtime's in worker/tsconfig.json. check:worker runs both.
  • check:browser names a compiled .js that differs from what its .ts compiles to apart from stale output, and asks for the change to move into the .ts first: a merge from a branch that predates the .ts can bring one, and a plain rebuild would drop it. build/AGENTS.md says the same. Merging main carried Keep the options a user chose in a select across reloads and revisions #7426's document-inputs change into the .ts this way.
  • The package references say a TypeScript library module keeps its types in the .ts beside the .js a widget imports.

Checks: tsc over browser/types/tsconfig.json and 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

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
@max-sixty max-sixty self-assigned this Nov 27, 2026

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@max-sixty
max-sixty merged commit 75d249f into main Nov 27, 2026
7 checks passed
@max-sixty
max-sixty deleted the claude/project-thread-aoeudz branch November 27, 2026 20:02
max-sixty added a commit that referenced this pull request Nov 27, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants