Skip to content

Instantly share code, notes, and snippets.

@ThetaSinner
Created August 1, 2025 15:47
Show Gist options
  • Select an option

  • Save ThetaSinner/9f3d97684223c6fac1dd0af5f40abfba to your computer and use it in GitHub Desktop.

Select an option

Save ThetaSinner/9f3d97684223c6fac1dd0af5f40abfba to your computer and use it in GitHub Desktop.
In your Cargo.toml:
```toml
# Feature: typescript
ts-rs = { workspace = true, features = ["bytes-impl"], optional = true }
[features]
typescript = [
"dep:ts-rs",
]
```
In your library code:
```rust
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[cfg_attr(feature = "typescript", derive(ts_rs::TS))]
#[cfg_attr(feature = "typescript", ts(export))]
pub struct Bundle {
pub app_id: String,
pub version: u32,
pub app: Bytes,
}
```
In a binary project that depends on the library:
```rust
use bundle::Bundle;
use ts_rs::TS;
fn main() {
Bundle::export_all_to("./@lib/pack").unwrap()
}
```
Then you can run the binary, and check in the generated types.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment