Add default constant exporting

This commit is contained in:
xazukx
2025-09-07 02:36:55 -06:00
parent 0480dcb964
commit c0790c1da2
7 changed files with 80 additions and 2 deletions
+19 -1
View File
@@ -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>>>,