Skip to content

Let runtime and package modules be TypeScript, compiled to the JavaScript pages load - #7424

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

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

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Requested by Maximilian · project thread

A runtime or bundled-package module may now be written as name.ts, beside the name.js the layer serves. The tree commits that .js, so installs from git, pages, tests and the kernel compiler still read JavaScript. Nothing on a user's machine compiles, and package authors still write plain JavaScript with no build.

This PR is the infrastructure, with one module (runtime/state/tab-store) converted as a pilot. Converting the runtime by directory follows in separate PRs, and Effect UI ports are written in .ts once this lands.

How it works

  • Compile (build/typescript.mjs): strip the types with node:module's stripTypeScriptTypes, so sources may use only erasable syntax (already required by erasableSyntaxOnly). Then format the result with oxfmt and the repo's settings.
    • The output keeps every comment and reads like the hand-written JavaScript.
    • The formatter hook and eslint, knip and dependency-cruiser accept the output as written, so no tool needs a list of generated files.
    • The cost: an output line sits near, not at, its .ts line.
  • Marking: the first line of a compiled .js names its source. check:browser refuses an output that is stale or whose source is gone, and the build removes the latter.
  • Type check: browser/types/tsconfig.json reads every .ts. When a .ts and a .js share a base name, tsc keeps the .ts.
  • Layer: layer.composed() drops .ts from what a layer composes and from what the serving runtime reads (runtime_selection), so a page neither loads nor copies sources. A model test covers both.
  • Formatter settings: .oxfmtrc.jsonc becomes oxfmt.config.ts, which the compiler imports. The pre-commit hook and package.json pin the same oxfmt version, and Dependabot leaves oxfmt alone, as it already does for esbuild and Rolldown.
  • Hooks: a pre-commit hook writes the outputs whenever a .ts or one of the build's own inputs changes.

A rule this reverses

checkRuntimeModules refused .ts under the runtime "so an edit reaches pages and tests without a build". An edit to a .ts module now reaches them only after node build/typescript.mjs runs, which the pre-commit hook does. Hand-written .js modules still need no build. Root AGENTS.md, build/AGENTS.md and browser/AGENTS.md now say this.

Checks

check:browser, check:tools, test:browser and test:runtime pass, as do tests/model (one failure, a permission test that fails when run as root) and pre-commit on the changed files. An independent review found 11 issues, all fixed here.


Generated by Claude Code

…ript pages load

A module may now be written as name.ts beside the name.js the layer serves.
build/typescript.mjs strips the types (erasable syntax only) and formats the
result with oxfmt, and the tree commits the output, so installs from git,
pages, tests and the kernel compiler still read JavaScript and nothing on a
user's machine compiles. This reverses the build's refusal of TypeScript under
the runtime: an edit to a .ts module now needs node build/typescript.mjs
(also run by a pre-commit hook) before it reaches a page.

- build: typescript.mjs writes and checks each output, and check:browser
  refuses a stale one or one whose source is gone.
- browser/types: the strict type check reads .ts modules, preferring a .ts
  over its compiled .js.
- layer: a layer composes no .ts, so pages neither load nor copy sources.
- knip reads the compiled .js in a module's place, as eslint and
  dependency-cruiser already do.
- runtime/state/tab-store is the first module in TypeScript.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01V22NWabEKzt7s5HiW4koa7
… hook

- oxfmt.config.ts replaces .oxfmtrc.jsonc, so the TypeScript build imports the
  formatter's settings rather than parsing JSONC; Dependabot leaves oxfmt to
  move with the pre-commit hook's pin.
- The serving runtime's file reader composes no .ts either (runtime_selection).
- The compile hook wakes on .ts sources and the build's own inputs only.
- The type check reads every .ts the compiler compiles.
- check:browser and the compiler share one finder of stale compiled modules.
- The install section points at build/AGENTS.md rather than restating it.

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
@max-sixty
max-sixty merged commit dffb8ea into main Nov 27, 2026
7 checks passed
@max-sixty
max-sixty deleted the claude/project-thread-aoeudz branch November 27, 2026 19:08
max-sixty added a commit that referenced this pull request Nov 27, 2026
<!-- claude-projects-attribution: {"github_login":"max-sixty"} -->
_Requested by **Maximilian** · [project
thread](https://claude.ai/code/project/chan_01HAT2svakg1fTA5kitqhX9w?thread=cmsg_01HAT2svakg1fTA5kitqhX9wERfAJinBvZtiP4jvQpWkPy)_

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, `@typedef`s 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 #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](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