-
Notifications
You must be signed in to change notification settings - Fork 119
Open
Labels
feature-requestA request for a new featureA request for a new feature
Description
Hi, just tried your library for the first time and really like it, also love its simplicity.
What lead me here is that I tried #[serde(flatten)] and got the error.
Here's one suggestion that would work pretty well IMHO, for serde struct flattening,
given for example this code:
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[typeshare]
pub struct Geolocation {
pub lat: f32,
pub long: f32,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[typeshare]
pub struct Meta {
#[serde(rename = "createdAt")]
pub created_at: chrono::DateTime<chrono::Utc>,
#[serde(rename = "updatedAt")]
pub updated_at: chrono::DateTime<chrono::Utc>,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[typeshare]
pub struct User {
email: String,
#[serde(flatten)]
geo: Geolocation,
#[serde(flatten)]
meta: Meta,
}would generate:
export interface Geolocation {
lat: number;
long: number;
}
export interface Meta {
createdAt: Date;
updatedAt: Date;
}
export interface User extends Geolocation, Meta {
email: string;
}I thought that would be a pretty good fit, especially since in Typescript an interface can inherit multiple interfaces, and it also does flatten the nested fields in the parent definition.
Let me know what you think, thanks for reading me :)
nicolasdialpad
Metadata
Metadata
Assignees
Labels
feature-requestA request for a new featureA request for a new feature