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

[feat] Generate Typescript Declaration from Structs in Rust #3586

Closed
d3rpp opened this issue Mar 2, 2022 · 5 comments
Closed

[feat] Generate Typescript Declaration from Structs in Rust #3586

d3rpp opened this issue Mar 2, 2022 · 5 comments

Comments

@d3rpp
Copy link

d3rpp commented Mar 2, 2022

Describe the problem

Typically, when you create a struct on the rust side, you need to declare the same struct on the typescript side using a .d.ts file or having a dedicated interface file. This normally isn't bad if not a little bit time consuming, though it does open up the floodgates for human error which can slow progress down significantly on larger codebases.

Describe the solution you'd like

There is a rust crate that can do this, however, which is simply a derive macro in typescript-definitions.

my knowledge of rust (and this code base) is very limited however it may be a good idea to have #[tauri::struct] macro in the same way we have #[tauri::command], which would release typescript definition files should a typescript mode be enabled in the projects tauri.conf.json.

The developer could then simply attach this #[tauri::struct] to any struct that are supposed to be accessed by the front end (and while its there, it may be a good idea to make it derive serde::Serialize if you can, idk).

Alternatives considered

Realistically this should only be a minor annoyance (that being, creating the .d.ts files yourself) until the codebases start scaling massively although it would be a nifty little feature, so if you absolute gods consider something like this it probably wouldn't be the highest priority at the moment all things considered.

Additional context

Overall this is purely an idea to improve the developer experience and overall, nothing will happen if this doesn't.

@nothingismagick
Copy link
Sponsor Member

Great idea! This kind of automation is nice for those lucky enough to struggle with TS in their day-to-day work.

@amrbashir
Copy link
Member

possibly duplicate of #1514

And tbh I don't know why should we implement this since there is already crates for it out there.

https://crates.io/crates/typescript-definitions
https://crates.io/crates/ts-rs

@FabianLars
Copy link
Member

FabianLars commented Mar 2, 2022

Yeah i think for this specific use-case it makes more sense to promote existing solutions (maybe integrate them in the docs or use them in an example).

@d3rpp
Copy link
Author

d3rpp commented Mar 2, 2022

possibly duplicate of #1514

And tbh I don't know why should we implement this since there is already crates for it out there.

https://crates.io/crates/typescript-definitions https://crates.io/crates/ts-rs

in a sense, yes it is, and my idea is to implement the crates you listed into the build system, so when you run tauri dev for example, it would create the type definitions for your structs and functions in an effort to streamline development

@lucasfernog
Copy link
Member

lucasfernog commented Jun 29, 2022

Closing as duplicate of #1514.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants