Replace ts-rs with typeshare for type generation#8
Open
antont wants to merge 1 commit into
Open
Conversation
Switch from ts-rs (derive macro + cargo test export hack) to typeshare (CLI tool by 1Password) for generating TypeScript interfaces from Rust structs. This gives us a cleaner generation workflow — typeshare parses source files directly instead of relying on test side effects. Key changes: - `#[derive(TS)] + #[ts(export)]` → `#[typeshare]` attribute - Per-type .ts files → single generated types.ts - `cargo test export_bindings` → `typeshare` CLI in scripts - TodoListResponse counts: i64 → i32 (typeshare doesn't support i64) - Option<T> now maps to optional fields (T?) instead of T | null Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Summary
cargo test export_bindingshack with a clean CLI tool that parses source files directly.tsfiles into a single generatedtypes.tsWhat changed
Cargo.tomlts-rs→typesharedependencysrc/models.rs#[derive(TS)] + #[ts(export)]→#[typeshare]; countsi64→i32src/handlers.rsas i32for the new field typescripts/generate-types.shcargo test→typeshareCLIscripts/check-types.shweb/src/types/generated/types.ts+ barrelindex.tsREADME.md,AGENTS.mdNotable behavioral differences
interfacevstype: typeshare generatesexport interface Foo { ... }instead ofexport type Foo = { ... }— functionally equivalent for plain data shapesOption<T>: maps tofield?: T(optional) instead offield: T | null— the frontendapi.tsalready converts undefined → null before sending JSONi64unsupported: typeshare rejectsi64(JSON precision concerns), so counts usei32which is more than sufficient for todo countsTest plan
cargo build --no-default-features --features sqlitecompilescargo test --no-default-features --features sqlitepasses (3/3)typeshare ./src --lang=typescriptgenerates correct outputnpx tsc --noEmit— TypeScript compiles with new typesscripts/generate-types.shworksscripts/check-types.shpasses🤖 Generated with Claude Code
Note
Medium Risk
Switches the Rust↔TypeScript type generation tool and changes generated type shapes (notably
Option<T>now becomes optional fields and counts move toi32), which can surface subtle contract mismatches if regeneration or callers lag behind.Overview
Replaces the Rust→TypeScript type bridge from
ts-rstotypeshare, updating Rust annotations (#[ts(export)]/TS→#[typeshare]), build dependencies, and docs.Updates type generation scripts to run the
typeshareCLI and consolidates frontend generated output from per-type files into a singleweb/src/types/generated/types.tswith a simplified barrel export.Adjusts API model types for typeshare limitations by changing todo count fields from
i64toi32and casting query results inlist_todosaccordingly; the generated TS types now representOption<T>as optional properties rather thannullunions.Written by Cursor Bugbot for commit ec2e997. This will update automatically on new commits. Configure here.