Skip to content

Type-check the runtime's JavaScript - #2803

Merged
max-sixty merged 2 commits into
mainfrom
agent-ae80d580b5a7785c6
Oct 14, 2026
Merged

max-sixty merged 2 commits into
mainfrom
agent-ae80d580b5a7785c6

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Strict tsc covered only build/browser/*.ts and the seven runtime modules marked // @ts-check; the other ~240 files under skills/leaf/assets/runtime/ were unchecked. pnpm run check:browser (and so pnpm run check, the PR test job and wt merge's pre-merge node-checks) now runs a second, non-strict checkJs program over every runtime module and the render checks pages import from /checks/. It found about 400 errors on main, and this PR clears them, mostly with JSDoc types, casts and narrowing.

How the gate is wired

  • build/browser/tsconfig.runtime.json is the non-strict program. paths resolves the runtime's rooted imports (/vendor/…, /runtime/…, /checks/…). Its include also pulls in Web Awesome's copy-button and input declarations, which add those tags to the tag map.

  • build/browser/tsconfig.json now includes every runtime module (unchecked unless it carries // @ts-check), so any module that opts into strict mode is checked strictly, whether or not the framework imports it.

  • build/browser/build.mjs (typecheck) runs both programs. tsc checks a JS file wherever an import reaches it, under the options of the program it's in, and has no per-file opt-out. So from the runtime program the build drops diagnostics in vendored third-party bundles and in files the strict program owns (.ts and // @ts-check). Every other diagnostic fails the build. The runtime program takes about 1.2 s.

  • The framework's types reach the runtime through a generated skills/leaf/assets/vendor/browser-runtime.d.ts (export * from "…/build/browser/index.ts"). Before, tsc inferred them from the compiled facade (types blanked) and the minified Lit bundle, which produced bogus errors such as render(): symbol on LitElement subclasses. This file ships in the layer like the .LICENSES.txt files beside it; nothing loads it at runtime.

  • build/browser/runtime-globals.d.ts declares, in one place:

    • what prepaint.js and bootstrap.js hang on <html> (lfInitial, lfStorage, lfKeyboard, lfChrome, lfViews, lfInputs, lfDocumentLifetime, lfStartupException, lfSample) and on window (lfSampleBridge);
    • the entry script's lfDocumentPort and lfRenderingState;
    • the events dispatched with a detail (lf-startup-failed, lf-command-invoked, lf-held-keys, lf-reveal, …);
    • the runtime's custom elements by tag, through a @typedef beside each class.

    The scripts' assignments are checked against these declarations.

Declarations corrected at their owner

application.ts didn't declare served-state fields the runtime already reads: files (each binding's stamp), browser.version_notes, browser.history, the undo entries' newest, the report feed's fields, and a to-do subject of kind element. thread/model.js now accepts the readonly thread snapshots its callers pass. askValue takes an Immutable widget. retainUserIntent, watchArrivals, rowWalk, closeLayer and similar functions get parameter types where defaults had inferred narrower ones.

Behavior the types exposed

  • Bug, fixed: queue-walk.js subscribed to effective.queues.questions, a field Call the user's list On me and the agent's On <agent>, in one cutover #2783 renamed to on_user. The selection was always undefined, so the walk never asked for a key repaint when On me emptied or filled. It now selects on_user. tests/runtime/queue-walk.test.mjs covers it: it fails on the old line and passes on the new one.
  • Dead code, removed: comment.create declared description: () => commentDestination().description. commentDestination stopped returning description in Let widgets own keyboard context bindings and hints #1654, so the field always answered undefined; every consumer resolves it through word()/descriptionOf, so removing it changes nothing.
  • Two edits change code shape without changing behavior: a boolean subtraction in a sort comparator now goes through Number(), and two Lit directives' render() now declare the values update() already received.

Checks

pnpm run check, including test:runtime (423 tests), passes. Focused pytest tests/model/test_unused_exports.py, test_interact_layer.py, test_distribution.py and test_module_url_delivery.py (238 tests) pass. Pre-commit passes on every changed file. An injected property error in a runtime module fails check:browser with the diagnostic.

Not covered yet: skills/leaf/assets/leaf.js and the packages' widget modules sit outside runtime/ and aren't in the runtime program.

This was written by Claude Code on behalf of max-sixty

max-sixty and others added 2 commits October 13, 2026 19:06
`pnpm run check:browser` now runs a second, non-strict `checkJs` program over every module under `skills/leaf/assets/runtime/` and the render checks pages import from `/checks/` (`build/browser/tsconfig.runtime.json`). The strict program now includes every runtime module, so each one marked `// @ts-check` is checked there. tsc checks a JavaScript file wherever an import reaches it and has no per-file opt-out, so the build drops runtime-program diagnostics in vendored third-party bundles and in files the strict program owns.

The framework's types reach the runtime through a generated `vendor/browser-runtime.d.ts` that re-exports `build/browser/index.ts`, instead of being inferred from the compiled, type-blanked facade and minified Lit. `build/browser/runtime-globals.d.ts` declares what the classic scripts hang on `<html>` and `window` (`lfInitial`, `lfStorage`, `lfChrome`, ...), the events the runtime dispatches with a detail, and the runtime's custom elements by tag.

About 400 diagnostics are cleared with JSDoc parameter types, casts and narrowing. Declarations that were wrong are corrected at their owner: `application.ts` now types the served state's `files`, `version_notes`, `history`, undo entries' `newest` and the report feed, which the runtime already read, and a to-do's `element` subject; `thread/model.js` takes readonly threads. One line the types found was dead: `comment.create`'s `description` read a field `commentDestination` stopped returning in #1654, so it always answered undefined; it is removed. Runtime behavior is otherwise unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts:
#	skills/leaf/assets/runtime/keyboard/disclosure.js
#	skills/leaf/assets/runtime/passages.js
#	skills/leaf/assets/runtime/thread/read.js
@max-sixty
max-sixty merged commit f836d27 into main Oct 14, 2026
3 checks passed
@max-sixty
max-sixty deleted the agent-ae80d580b5a7785c6 branch October 14, 2026 02:27
max-sixty added a commit that referenced this pull request Oct 14, 2026
…in pages (#2850)

`pnpm run check:browser` now type-checks `leaf.js`, the kernel's
`widgets/`, and every bundled package's `initial.js` and widget modules
under the same non-strict `checkJs` program #2803 added for the runtime.
Pages no longer carry `vendor/browser-runtime.d.ts`: the build stops
generating it, and a freshly vendored page (`leaf page init --package
diff --package playwright`) has no `.d.ts` file.

## How the framework's types reach the check now

The generated declaration file sat beside `vendor/browser-runtime.js` so
that tsc would prefer it over the compiled, type-blanked facade. Since
it lived in the layer's `vendor/`, `leaf page init` copied it into every
page. Instead:

- `build/browser/tsconfig.json` holds one `paths` map, which
`tsconfig.runtime.json` now `extends`. It resolves the rooted paths a
page serves, including each package's `vendor/` and `widgets/`, and maps
`/vendor/browser-runtime.js` to `index.ts`.
- `paths` applies only to non-relative specifiers, so the 39 runtime
modules (and `leaf.js`) that imported the facade as
`../vendor/browser-runtime.js` now import `/vendor/browser-runtime.js`.
That was already the convention: four runtime modules used it, and
`layer_import_map` says every layer module names its dependencies by
rooted path. The import map, export, kernel bundle and Node test hooks
all resolve it already, and a probe of `pr-walkthrough` boots with no
errors.
- A relative facade import would silently type against the blanked
facade, so the runtime's ESLint ownership rule
(`semanticStoreOwnershipRule`) now refuses one, with a test in
`build/browser/architecture.test.mjs`.
- The build's diagnostic filter drops diagnostics in each package's
`vendor/` as well as the layer's.

## What the wider check found

- **Dead wiring:** `leaf.js` passed `foldMarginEntryOptions` and
`unfoldedMarginEntries` to `createReactionController`, which stopped
reading them in #2753; the overlay no longer exports either, so both
were always `undefined`. Removed, with the stale field in
`tests/runtime/reactions.test.mjs`.
- **Wrong declarations, corrected at their owner:** `claimTraversals`
declared that a claim receives a string, but it receives the traversal's
`URL` (`lf-tabs` reads `url.hash`). `readDiffCoordinate` now declares
the coordinate it returns.
- `lf-trace` used `peer?.#bookmarks`. tsc refuses that as a grammar
error (TS18030), which stopped the whole program, so it now reads `peer
&& peer.#bookmarks`.
- Web Awesome's `wa-comparison` and `wa-radio` declarations join the
program, so `offer()` and `createElement` type those controls.

The rest are JSDoc casts and parameter types. I found no behavior bug.

## Checks

`pnpm run check:framework` (browser build check, including both type
programs, plus 110 Node tests) and `pnpm run test:runtime` (470 tests)
pass. Focused pytest on `test_unused_exports.py`,
`test_interact_document.py`, `test_interact_layer.py`,
`test_distribution.py` and `test_module_url_delivery.py` passes (440
tests), as does pre-commit, including ESLint over every runtime module.
An error injected into a package widget fails `check:browser`.

> _This was written by Claude Code on behalf of max-sixty_

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[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.

2 participants