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
Add type_as attribute to specta #91
Add type_as attribute to specta #91
Conversation
`type_as = <Ident>` attribute overrides the type of the field in the generated type definition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this! Super cool idea to override the Rust type that is used rather than writing custom typescript.
I'd like the feature to mirror ts-rs
a bit more, but you've already done quite a good job.
I might rebase this PR onto a bunch of new changes to Specta that are being made in preparation to make it more of a standalone library, I'll handle that though.
Also would you mind explaining why you need type overrides, and why you picked Specta over |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your time. Looks great!
Oh, sorry I didn't have the time to address your comments, thanks for the corrections. Our main problem was that the messages in our tauri app included types from 3rd party crates that we normally just serialize to string, but we can't have them implement Type. The reason we would like to use specta is its ability to generate all referenced type definitions recursively. With ts-rs we have a huge list of types that need to be printed, and it needs to be updated manually. Whereas with specta, it would just be a single call, since we already have all relevant types in an enum anyway. |
We were looking into using specta in our project, but ran into the issue of needing an escape hatch for certain types that can't (easily) implement
Type
. This solution is similar to ts_rs's#[ts(type = "..")]
attribute.#[specta(type_as = <Ident>)]
on a field overrides its type in the generated type definition with the type of the identifier.Example:
Any feedback is super appreciated!