Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion for #[serde(flatten)] #114

Open
Roms1383 opened this issue May 6, 2023 · 0 comments · May be fixed by #115
Open

Suggestion for #[serde(flatten)] #114

Roms1383 opened this issue May 6, 2023 · 0 comments · May be fixed by #115
Labels
feature-request A request for a new feature

Comments

@Roms1383
Copy link

Roms1383 commented May 6, 2023

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 :)

@Roms1383 Roms1383 linked a pull request May 7, 2023 that will close this issue
@snowsignal snowsignal added the feature-request A request for a new feature label May 10, 2023
@Lucretiel Lucretiel linked a pull request May 25, 2023 that will close this issue
Progdrasil added a commit to 1Password/passkey-rs that referenced this issue Dec 11, 2023
This is because `serde(flatten)` is not supported in typeshare, see 1Password/typeshare#114 for more info
Progdrasil added a commit to 1Password/passkey-rs that referenced this issue Dec 11, 2023
This is because `serde(flatten)` is not supported in typeshare, see 1Password/typeshare#114 for more info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A request for a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants