Skip to content

feat(ts): type-check the whole output before a translation succeeds - #376

Merged
moq-bot[bot] merged 4 commits into
mainfrom
quest/m3/ts-check-output
Nov 1, 2026
Merged

moq-bot[bot] merged 4 commits into
mainfrom
quest/m3/ts-check-output

Conversation

@kixelated

@kixelated kixelated commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator

Completes quest/m3/ts-check-output.md.

Problem

Translation succeeded on output tsc rejects. Only the check module of bindings was type-checked, so a typing gap surfaced in the consumer's own tsc, far from the Rust that caused it. Reproduced on main with a generic type's Vec<T> at u8 (the gap ts-generic-byte-fields tracks): rust2-ts exits 0, then tsc reports lib.Window.ts(18,20): error TS2339: Property 'data' does not exist on type 'u8[]' and lib.ts(8,53): error TS2740: Type 'ByteVec' is missing ....

Approach

  • The existing bindings tsc run (moved from lower/bind.rs to ts/src/check.rs, since it now checks the whole output) lists every translated module in its project beside the check module. One tsc process, same settings as before: the runtime's strictness without the unused-name lints.
  • print::module returns its source-map tokens and each item's first line, and Program::write returns every module as printed. A diagnostic in a translated module reports at the Rust span of the last mapping at or before it in the same item, else at the item's symbol span, else without a span. Source keeps rustc's file start so a Loc maps back to a Span.
  • The message names the TS position and blames the translator: lib.ts:8:47 doesn't type-check, which is a bug in rust2-ts: error TS2740: .... Each (span, message) is reported once, so a generic function's instances fail once.
  • A wrong binding also breaks the translated code that calls it (seen in bind/wrong.toml: 7 extra errors in harness.ts). Errors in translated modules are reported only when no binding or other file failed. Translation fails in both cases.
  • The check module's lines map to their check by the printed item starts, not by scanning the text for function check$N.
  • Fixture: reject/mistyped.toml translates that gap and expects both errors at their Rust spans, with the output removed.

Cost on moq-net's pinned translation (19 modules, 90 files with the runtime and libs): the tsc run takes 0.20 s wall, 0.8 s CPU, 100 MB (8 runs, tsc 7.0.2). The whole translation takes about 15 s. End-to-end timings with and without the check differ by less than host noise.

Impact

  • Translation fails, at a Rust span, on output tsc rejects, where it succeeded before. ts/MIGRATE.md notes it.
  • Every translation needs tsc 7.0 or later on PATH, not only one with bindings. The flake's package and dev shell already provide it.
  • No change to the output's text.

Alternatives

  • A second tsc run with the runtime's full settings (noUnusedLocals): it would also catch unused names, but those are lint, binding files may leave them, and it doubles the process cost. just ts test and just ts moq still check the fixtures and moq with them.
  • include: ["../**/*.ts"] instead of listing files: it would check hand-written files a caller keeps in the output directory, which clean deliberately keeps.
  • Opt-in check: the quest asks for failing translation, and the cost is about 1% of a moq-net translation, so it is always on.

Choices made without asking: errors in translated code are held back while a binding fails; a diagnostic outside any mapping reports without a span rather than at a guessed one.

Follow-ups

  • The source map is coarse for some statements: a function's tail return maps to its closing } and a call to its method name, so a check error points there. A finer map would sharpen these spans. Not recorded as a quest yet.
  • ts-generic-byte-fields now notes that its fix moves the mistyped case to another typing gap.

Checks

just ci passed locally inside nix develop on 4dd8cf6.

Review

(written by Claude Opus 5.5)

🤖 Generated with Claude Code

@kixelated kixelated changed the title Type-check the output before success feat(ts): type-check the whole output before a translation succeeds Nov 1, 2026
@kixelated
kixelated marked this pull request as ready for review November 1, 2026 06:55
@coderabbitai

coderabbitai Bot commented Nov 1, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 55 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7aa9ecd0-34a6-48d1-8194-b455a1b9d840
Commits

Reviewing files that changed from the base of the PR and between 06614b5 and 4dd8cf6.

Files selected for processing: 18
  • quest/m3/README.md
  • quest/m3/ts-check-output.md
  • quest/m3/ts-generic-byte-fields.md
  • quest/m3/ts-tsrs.md
  • ts/MIGRATE.md
  • ts/README.md
  • ts/fixtures/reject/census.md
  • ts/fixtures/reject/mistyped.toml
  • ts/fixtures/reject/mistyped.txt
  • ts/fixtures/reject/src/lib.rs
  • ts/src/check.rs
  • ts/src/driver.rs
  • ts/src/lower/bind.rs
  • ts/src/lower/mod.rs
  • ts/src/main.rs
  • ts/src/print.rs
  • ts/src/program.rs
  • ts/tests/fixtures.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@kixelated
kixelated enabled auto-merge (squash) November 1, 2026 06:56
@moq-bot
moq-bot Bot merged commit d12077a into main Nov 1, 2026
1 check passed
@moq-bot
moq-bot Bot deleted the quest/m3/ts-check-output branch November 1, 2026 07:17
kixelated added a commit that referenced this pull request Nov 1, 2026
…yte-fields

Drops the reject fixture's `mistyped` case, which #376 wrote through the typing gap
this branch closes: no other typing gap that translation leaves to `tsc` is known.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant