-
Notifications
You must be signed in to change notification settings - Fork 99
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
How can I typeshare
a type that has a field that is not under my control?
#124
Comments
#[typeshare]
struct Id(#[typeshare(serialized_as = "string")] uuid::Uuid); results in: export type Id = string; If you generate TypeScript out of it. |
Excellent! Thank you. |
@lukaszlew It is documented here. But tbh it's definitely jarring that these docs are not really mentioned anywhere (at least as far as I know). Also, it seems like it uses mdbook, but the docs README doesn't really explain that fact or how to render the book locally. I think it would be an important addition to increase the visibility of these docs. Perhaps even linking the relevant book docs in the docs.rs crate documentation (which are incredibly sparse). At least in the main README. |
@LouisGariepy I agree that the docs require a bit of a makeover. The TypeScript |
So now I know how to generate annotations for types of fields that I don't control
How about if it is the wrapping struct that I don't control? E.g.:
won't export the |
@lukaszlew I believe you can use the newtype idiom, see an example in the tests: https://github.com/1Password/typeshare/tree/main/core/data/tests/test_optional_type_alias and the idiom documentation: https://doc.rust-lang.org/rust-by-example/generics/new_types.html |
E.g.
would not add Uuid itself to type-shared types.
Please advise.
The text was updated successfully, but these errors were encountered: