From 877bdcc284482b908518ab56be4e9d6eb6cf4672 Mon Sep 17 00:00:00 2001 From: tomjw64 Date: Thu, 24 Aug 2023 09:02:03 -0500 Subject: [PATCH] Add field annotations docs --- docs/src/usage/annotations.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/docs/src/usage/annotations.md b/docs/src/usage/annotations.md index 7227619f..7b528eea 100644 --- a/docs/src/usage/annotations.md +++ b/docs/src/usage/annotations.md @@ -103,7 +103,26 @@ This would generate the following Kotlin code: typealias Options = String ``` +### Override Type for a Field +You can also use language-specific arguments to tell Typeshare to treat +the a field as a type in a particular output language. For example, +```rust +#[typeshare] +struct MyStruct { + #[typeshare(typescript(type = "0 | 1"))] + oneOrZero: u8, +} +``` +would generate the following Typescript code: +```typescript +export interface MyStruct { + oneOrZero: 0 | 1; +} +``` +The `type` argument is supported for all output languages, however Typescript +also supports the optional `readonly` argument (e.g. `typescript(readonly, type= "0 | 1")`) +to make the output property readonly. ## The `#[serde]` Attribute