Created
August 1, 2025 15:47
-
-
Save ThetaSinner/9f3d97684223c6fac1dd0af5f40abfba to your computer and use it in GitHub Desktop.
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
| 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