Repository navigation
Type-check the runtime's JavaScript - #2803
Merged
Merged
Conversation
`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
leaf-agent
approved these changes
Oct 14, 2026
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]>
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.
Strict
tsccovered onlybuild/browser/*.tsand the seven runtime modules marked// @ts-check; the other ~240 files underskills/leaf/assets/runtime/were unchecked.pnpm run check:browser(and sopnpm run check, the PRtestjob andwt merge's pre-mergenode-checks) now runs a second, non-strictcheckJsprogram 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.jsonis the non-strict program.pathsresolves the runtime's rooted imports (/vendor/…,/runtime/…,/checks/…). Itsincludealso pulls in Web Awesome'scopy-buttonandinputdeclarations, which add those tags to the tag map.build/browser/tsconfig.jsonnow 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 (.tsand// @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 asrender(): symbolonLitElementsubclasses. This file ships in the layer like the.LICENSES.txtfiles beside it; nothing loads it at runtime.build/browser/runtime-globals.d.tsdeclares, in one place:prepaint.jsandbootstrap.jshang on<html>(lfInitial,lfStorage,lfKeyboard,lfChrome,lfViews,lfInputs,lfDocumentLifetime,lfStartupException,lfSample) and onwindow(lfSampleBridge);lfDocumentPortandlfRenderingState;lf-startup-failed,lf-command-invoked,lf-held-keys,lf-reveal, …);@typedefbeside each class.The scripts' assignments are checked against these declarations.
Declarations corrected at their owner
application.tsdidn'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 kindelement.thread/model.jsnow accepts the readonly thread snapshots its callers pass.askValuetakes anImmutablewidget.retainUserIntent,watchArrivals,rowWalk,closeLayerand similar functions get parameter types where defaults had inferred narrower ones.Behavior the types exposed
queue-walk.jssubscribed toeffective.queues.questions, a field Call the user's list On me and the agent's On <agent>, in one cutover #2783 renamed toon_user. The selection was alwaysundefined, so the walk never asked for a key repaint when On me emptied or filled. It now selectson_user.tests/runtime/queue-walk.test.mjscovers it: it fails on the old line and passes on the new one.comment.createdeclareddescription: () => commentDestination().description.commentDestinationstopped returningdescriptionin Let widgets own keyboard context bindings and hints #1654, so the field always answeredundefined; every consumer resolves it throughword()/descriptionOf, so removing it changes nothing.Number(), and two Lit directives'render()now declare the valuesupdate()already received.Checks
pnpm run check, includingtest:runtime(423 tests), passes. Focused pytesttests/model/test_unused_exports.py,test_interact_layer.py,test_distribution.pyandtest_module_url_delivery.py(238 tests) pass. Pre-commit passes on every changed file. An injected property error in a runtime module failscheck:browserwith the diagnostic.Not covered yet:
skills/leaf/assets/leaf.jsand the packages' widget modules sit outsideruntime/and aren't in the runtime program.