Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript type generation directly from Rust types #2093

Open
aumetra opened this issue Apr 9, 2024 · 1 comment
Open

TypeScript type generation directly from Rust types #2093

aumetra opened this issue Apr 9, 2024 · 1 comment
Labels
enhancement New feature or request schema cosmwasm-schema crate
Milestone

Comments

@aumetra
Copy link
Member

aumetra commented Apr 9, 2024

At the moment we generate the TypeScript types by outputting JSON Schema files and then converting them into TypeScript types.
This not only loses some type information but it also complicates the setup.

Since TypeScript is pretty much the only language that clients are written in, we decided through internal discussion that phasing out JSON Schemas in favour of generating TypeScript types is a worthwhile endeavour.

This drops our dependence on the schemars crate in favour of using the ts-rs crate to generate these types.

@aumetra aumetra added enhancement New feature or request schema cosmwasm-schema crate labels Apr 9, 2024
@aumetra aumetra added this to the 2.1.0 milestone Apr 9, 2024
@aumetra aumetra modified the milestones: 2.1.0, 2.2.0 Apr 19, 2024
@aumetra
Copy link
Member Author

aumetra commented May 3, 2024

Just adding this here to not forget: apparently some people are not using the cw_serde macro to generate their types (ref: https://twitter.com/kromssten/status/1747287780214935754), so simply changing the generate_api macro to unconditionally emit TS definitions won't cut it. Since that would break these users.

Technically we have two options:

  1. Call it acceptable breakage and say anything besides the cw_serde macro isn't supported
  2. Implement a specialization hack based on auto-ref (see: https://docs.rs/spez/latest/spez/)

I think the second option would probably be nicer for our consumers since it doesn't break anything for them, but it would increase the macro complexity a bit (but I don't think to a big enough degree to really matter)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request schema cosmwasm-schema crate
Projects
None yet
Development

No branches or pull requests

2 participants
@aumetra and others