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

Mismatch between ts-rs's idea of camelCase and serde's #165

Closed
ilyvion opened this issue Aug 17, 2023 · 2 comments · Fixed by #184
Closed

Mismatch between ts-rs's idea of camelCase and serde's #165

ilyvion opened this issue Aug 17, 2023 · 2 comments · Fixed by #184

Comments

@ilyvion
Copy link

ilyvion commented Aug 17, 2023

I have a type like this:

#[derive(Debug, Serialize, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export)]
pub struct ItemImageList {
    pub id: u32,
    pub crc32c_hash: u32,
}

The generated camelCase field name from serde for the field crc32c_hash is crc32cHash. ts-rs, on the other hand, decides to generate the following TS file:

// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export interface ItemImageList { id: number, crc32CHash: number, }

This obviously leads to problems when trying to use the ItemImageList interface in TS to read JSON serialized by serde.

The solution for me for the time being, has been to slap #[ts(rename = "crc32cHash")] on the field. But the question is, should there actually be a discrepancy here?

@NyxCode
Copy link
Collaborator

NyxCode commented Aug 18, 2023

Thanks for opening the issue!
No, this is definetely not intentional. We use the inflector crate for converting between the inflection. Unfortunately, it seems like it isn't 100% compatible with serde. I suppose we need to figure it if we can directly use serde's logic for this conversion, or if has to be re-implemented.

@ilyvion
Copy link
Author

ilyvion commented Dec 7, 2023

Apparently this isn't the only crate being "hit" by this mismatch. whatisinternet/Inflector#85

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants