Repository navigation
docs(spike): Would TypeScript make this webview safer? (#692) - #742
Merged
Merged
Conversation
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>
…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>
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.
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 --noEmitwithcheckJsis the right tool, used as a checker rather than as a language. It is alighter 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.TRUNCATED_MARKafter the exporter dropped it — an unresolved import.loginSaid— aReferenceErrorin strict mode.Neither needs a type. Both are rules a linter has had since 2013. And both already have
guards:
tests/overlay-imports.test.jsandtests/no-undeclared-assignment.test.jswere 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 andwere 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
src/no-undef,import/named)tsc --checkJs, loose__TAURI__, 16 DOM casts, 3 one-linerstsc --checkJs,strictTwenty-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:
The dependency comparison comes out backwards
Today: zero npm dependencies, no lockfile, no
node_modules, CI never installs.typescripteslint+globals+eslint-plugin-importThe linter is the heavy supply-chain commitment; the type checker depends on nothing. If
we break the zero-dependency position,
tscis the cheaper break and catches more.The build step is worse here than in a normal web project
frontendDistis"../src"— the files we read are the files we ship. Verified: pointit at a missing directory and the Rust build fails at compile time.
So under a full port, a built
dist/becomes a prerequisite for everycargo check,cargo buildandcargo test— including pull requests that touch no JavaScript. Theearlier draft listed this as unverified. It is the strongest argument against option 3.
Smaller losses:
tests/as.tsneeds Node 22.18+ (Node 20 here fails); the vendoredmarkedsha256 pin would still pass but stop describing what ships; debugging needssource maps.
What we would gain, stated fairly
The mechanical class — misread name, wrong case, wrong nullability.
probe/misread.jsmakes six such mistakes and
tsccatches all six. It has not bitten yet. Editorautocomplete on payloads, which a generated
.d.tsgives 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/*.jsfile in the samecommit. Neither #654 (an ignored return value) nor #659/#678 (a field that does not
exist) would have been caught.
Recommendation
standing tax on every Rust change.
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.
ts-rs-proto/proves generation works: stalefixture 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.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.jsso it can be tested. That has caught more than a typechecker would have.
Reproduce
Also carries a one-line pre-commit fix this spike's nested
Cargo.lockexposed: all threeCargo.lockexcludes were anchored at the repo root, sopretty-format-tomlreformatteda nested lock that cargo then rewrote.
#692 stays open for the decision.
— Claude Code agent
🤖 Generated with Claude Code