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

Is it possible to disable default features for TS-RS? #91

Open
gluax opened this issue Dec 17, 2024 · 1 comment
Open

Is it possible to disable default features for TS-RS? #91

gluax opened this issue Dec 17, 2024 · 1 comment

Comments

@gluax
Copy link

gluax commented Dec 17, 2024

Hey!

I don't know if this would break anything for qubit but I ask because I have the following use case:

I'm fetching data from a request on the rust side which expects the JSON to be in snake_case.
But on the TS my linter yells at me for not using camelCase.

So I did the following:

#[derive(Debug, Serialize, Deserialize, Clone, TS)]
#[serde(rename_all = "snake_case")]
#[ts(rename_all = "camelCase")]
pub struct PubkeyParams {
    pub activation_delay:       String,
    pub activation_threshold_percent: u8,
}

however, it seems the serde-compat feature, enabled by default` overrides the ts-rs directive.
We can always enable this feature ourselves from where we import it if we want it.

Or maybe this is a issue I should put on ts-rs, that ts directives should override the serde directive if it exists.

EDIT:

I did wind up making an issue over on ts-rs as well: Aleph-Alpha/ts-rs#375

@andogq
Copy link
Owner

andogq commented Dec 17, 2024

https://serde.rs/container-attrs.html#rename_all

I'm not 100% sure it would work, but you could try this form of serde rename

#[serde(rename_all(serialize = "camelCase", deserialize = "snake_case"))]

That should give you the functionality you're looking for, as ts-rs is only used for generating the types, the serialisation is still handled by serde.

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

No branches or pull requests

2 participants