It also supports enums, so the following Rust types:
/// Doc comments are preserved too!
#[tsync]
struct Book {
/// Name of the book.
name: String,
/// Chapters of the book.
chapters: Vec<Chapter>,
/// Reviews of the book
/// by users.
user_reviews: Option<Vec<String>>,
#[serde(flatten)]
book_type: BookType,
}
#[tsync]
#[derive(Serialize)]
#[serde(tag = "type")]
enum BookType {
Fiction { genre: String },
NonFiction { subject: String },
}
Will generate these TypeScript types:
/** Doc comments are preserved too! */
export type Book = BookType & {
/** Name of the book. */
name: string;
/** Chapters of the book. */
chapters: Array<Chapter>;
/**
* Reviews of the book
* by users.
*/
user_reviews?: Array<string>;
}
export type BookType =
| BookType__Fiction
| BookType__NonFiction;
type BookType__Fiction = {
type: "Fiction";
genre: string;
};
type BookType__NonFiction = {
type: "NonFiction";
subject: string;
};
Addresses #48
Will convert these Rust types:
To these TypeScript types:
It also supports enums, so the following Rust types:
Will generate these TypeScript types: