Open lukaszlew opened 1 year ago
@lukaszlew
#[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. Consider adding it to the documentation.
@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 readonly
attribute is also not mentioned at all AFAIK. There's probably a lot of other things missing too.
So now I know how to generate annotations for types of fields that I don't control
#[typeshare]
struct Id(#[typeshare(serialized_as = "string")] uuid::Uuid);
How about if it is the wrapping struct that I don't control? E.g.:
#[typeshare]
type = Result<String, String>
won't export the Result
itself.
@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.