mirror of
https://github.com/xazukx/ts-rs.git
synced 2026-11-18 22:30:26 +00:00
Add default constant exporting
This commit is contained in:
+19
-1
@@ -28,6 +28,7 @@ enum Gender {
|
||||
|
||||
#[derive(Serialize, TS)]
|
||||
#[ts(export)]
|
||||
#[ts_constant(default, export_to = "constants.ts")]
|
||||
struct User {
|
||||
user_id: i32,
|
||||
first_name: String,
|
||||
@@ -41,6 +42,22 @@ struct User {
|
||||
created_at: NaiveDateTime,
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl Default for User {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
user_id: 101,
|
||||
first_name: "John".to_string(),
|
||||
last_name: "Doe".to_string(),
|
||||
role: Role::User,
|
||||
family: Vec::new(),
|
||||
gender: Gender::Male,
|
||||
token: Uuid::default(),
|
||||
created_at: NaiveDateTime::from_timestamp(0, 0),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, TS)]
|
||||
#[serde(tag = "type", rename_all = "snake_case")]
|
||||
#[ts(export)]
|
||||
@@ -98,9 +115,10 @@ enum InlineComplexEnum {
|
||||
U(Box<User>),
|
||||
}
|
||||
|
||||
#[derive(Serialize, TS)]
|
||||
#[derive(Serialize, TS, Default)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export)]
|
||||
#[ts_constant(default, export_to = "constants.ts")]
|
||||
struct ComplexStruct {
|
||||
#[serde(default)]
|
||||
pub string_tree: Option<Rc<BTreeSet<String>>>,
|
||||
|
||||
Reference in New Issue
Block a user