Skip to content

docs(spike): Would TypeScript make this webview safer? (#692) - #742

Merged
omesser merged 2 commits into
mainfrom
spike/typescript-692
Sep 15, 2026
Merged

omesser merged 2 commits into
mainfrom
spike/typescript-692

Conversation

@omesser

@omesser omesser commented Sep 15, 2026 •

Copy link
Copy Markdown
Owner

Spike for #692. Report is spike/typescript-692/REPORT.md. No production code changes.

The question is not what a migration would cost to perform — an error count answers that,
and it is the boring part. The question is whether we would be safer afterwards, and
what the tooling costs. This answers those.

Answer

Keep writing .js. Do not add a build step.

If we want static analysis anyway — there is a decent case — then tsc --noEmit with
checkJs is the right tool, used as a checker rather than as a language. It is a
lighter dependency than a linter and catches strictly more.

Types would have caught none of the bugs this webview has shipped

Nineteen commits fix a bug in src/*.js. I read every diff.

Count
Needed type annotations 0
Caught by static analysis, no types needed 2 (#652, #738)
Logic, timing, copy, missing feature 17

Neither needs a type. Both are rules a linter has had since 2013. And both already have
guards
: tests/overlay-imports.test.js and tests/no-undeclared-assignment.test.js
were each added in their own fix commit. The second admits in its header that it "is not
a substitute for a real checker."

Limit of this evidence: a census of fix() commits sees only defects that shipped and
were noticed. Bugs a checker stops someone from writing leave no trace. "0 of 19" is the
best evidence available and it points one way, but it is not the whole truth.

Signal versus noise on today's code

Tool On current src/
eslint (no-undef, import/named) 0 errors, 1 warning — a real dead variable
tsc --checkJs, loose 29 errors — 10 __TAURI__, 16 DOM casts, 3 one-liners
tsc --checkJs, strict 337

Twenty-six of the 29 are ceremony: casts that assert what the code already knew. A cast is
not a caught bug. Roughly 3 of 29 are about correctness.

Both checkers catch both historical bugs, measured by reintroducing each:

eslint  →  'loginSaid' is not defined                       no-undef
           TRUNCATED_MARK not found in './bubble.js'        import/named
tsc     →  TS2304: Cannot find name 'loginSaid'.
           TS2305: Module '"./bubble.js"' has no exported member 'TRUNCATED_MARK'.

The dependency comparison comes out backwards

Today: zero npm dependencies, no lockfile, no node_modules, CI never installs.

Packages Size
typescript 1 (zero transitive deps) 23 MB
eslint + globals + eslint-plugin-import 194 (34 direct) 34 MB

The linter is the heavy supply-chain commitment; the type checker depends on nothing. If
we break the zero-dependency position, tsc is the cheaper break and catches more.

The build step is worse here than in a normal web project

frontendDist is "../src" — the files we read are the files we ship. Verified: point
it at a missing directory and the Rust build fails at compile time.

error: proc macro panicked
    --> src-tauri/src/main.rs:2805:16
     |
2805 |         .build(tauri::generate_context!())
     = help: message: The `frontendDist` configuration is set to `"../dist"`
             but this path doesn't exist

So under a full port, a built dist/ becomes a prerequisite for every cargo check,
cargo build and cargo test — including pull requests that touch no JavaScript. The
earlier draft listed this as unverified. It is the strongest argument against option 3.

Smaller losses: tests/ as .ts needs Node 22.18+ (Node 20 here fails); the vendored
marked sha256 pin would still pass but stop describing what ships; debugging needs
source maps.

What we would gain, stated fairly

The mechanical class — misread name, wrong case, wrong nullability. probe/misread.js
makes six such mistakes and tsc catches all six. It has not bitten yet. Editor
autocomplete on payloads, which a generated .d.ts gives without the port. And #706,
which is the real argument: Settings moves into the webview and reads the largest payload
this app has.

The boundary-drift argument the issue leads with does not survive the history: 31 commits
changed a struct the webview listens to, and 30 changed a src/*.js file in the same
commit. Neither #654 (an ignored return value) nor #659/#678 (a field that does not
exist) would have been caught.

Recommendation

  1. No port, no build. 0 of 19 bugs needed types; the compile-time coupling is a
    standing tax on every Rust change.
  2. If we add a checker, tsc --noEmit --checkJs — one zero-dependency package.
    Running it non-blocking for a while is a cheap way to see if the 26-casts-for-3-findings
    trade is worth it.
  3. Option 2 when something needs it. ts-rs-proto/ proves generation works: stale
    fixture test, six dev-only crates, nothing at runtime. First customer is refactor(settings): Replace the three native Settings renderers with one webview #706's
    settings payload, not chat.js.
  4. Revisit after refactor(settings): Replace the three native Settings renderers with one webview #706. That is the change that could move this answer.

The status quo is not "no safety" — it is 203 tests, plus a habit visible in #691 and #694
of extracting logic out of chat.js so it can be tested. That has caught more than a type
checker would have.

Reproduce

cp spike/typescript-692/marked.esm.d.ts.stub src/vendor/marked.esm.d.ts
npx -y -p typescript@5 tsc --noEmit -p spike/typescript-692/tsconfig.option1-loose.json
rm src/vendor/marked.esm.d.ts

cd spike/typescript-692/ts-rs-proto && cargo test   # 16 tests, stale check included
git log --no-merges --pretty='%h|%s' -- 'src/*.js' | grep -iE '\|fix'   # the census

Also carries a one-line pre-commit fix this spike's nested Cargo.lock exposed: all three
Cargo.lock excludes were anchored at the repo root, so pretty-format-toml reformatted
a nested lock that cargo then rewrote.

#692 stays open for the decision.

— Claude Code agent

🤖 Generated with Claude Code

Stay on .js. Add a check, not a build: `tsc --noEmit` with `checkJs`, plus
payload types generated from Rust by ts-rs under `#[cfg(test)]`. Not a full
TypeScript port — Tauri embeds `frontendDist` at compile time, so that would
put a `tsc` run in front of every `cargo test`.

The check found a real crash on its first run, which shipped as #737.

Carries a pre-commit fix the spike's own nested Cargo.lock exposed: all three
`Cargo.lock` excludes were anchored at the repo root, so `pretty-format-toml`
reformatted a nested lock that cargo then rewrote.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@omesser omesser added documentation Improvements or additions to documentation maintenance Dependency and tooling upkeep research Defining or executing a research into an aspect: tech, direction, decision labels Sep 15, 2026
…hey cost

The first draft counted compiler errors on a hypothetical migration and treated
that as the answer. It is the expected part, and it settles nothing.

Read all 19 commits that fix a bug in src/*.js. None needed type annotations.
Two were static-analysis preventable, both already guarded by tests added in
their own fix commits. Measured the rest of the decision: eslint is 194 packages
against typescript's 1, and a missing frontendDist panics generate_context! at
compile time, so a build step taxes every Rust-only change.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@omesser omesser changed the title docs(spike): Should the webview move to TypeScript? (#692) docs(spike): Would TypeScript make this webview safer? (#692) Sep 15, 2026
@omesser omesser added needs-triage Maintainer needs to evaluate this issue ready-for-human Requires human implementation labels Sep 15, 2026
@omesser
omesser merged commit 18fa79a into main Sep 15, 2026
9 checks passed
@omesser
omesser deleted the spike/typescript-692 branch September 15, 2026 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation maintenance Dependency and tooling upkeep needs-triage Maintainer needs to evaluate this issue ready-for-human Requires human implementation research Defining or executing a research into an aspect: tech, direction, decision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant