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

Bug: Fields starting with numeric literal need to be quoted #37

Open
Pistonight opened this issue Oct 13, 2023 · 1 comment · May be fixed by #38 or #46
Open

Bug: Fields starting with numeric literal need to be quoted #37

Pistonight opened this issue Oct 13, 2023 · 1 comment · May be fixed by #38 or #46

Comments

@Pistonight
Copy link

Pistonight commented Oct 13, 2023

Input

use serde::{Serialize, Deserialize};
use tsify::Tsify;
#[derive(Serialize, Deserialize, Tsify)]
#[tsify(from_wasm_abi, into_wasm_abi)]
pub struct OneX {
    #[serde(rename = "1x")]
    pub one_x: f64;
}

Output

export interface One {
    1x: number
}

Expected

1x needs to be quoted

export interface One {
    "1x": number
}
@Pistonight Pistonight changed the title Bug: Some fields need to be quoted Bug: Fields starting with numeric literal need to be quoted Oct 13, 2023
@Pistonight Pistonight linked a pull request Oct 13, 2023 that will close this issue
@Swolebrain
Copy link

This isn't just for numeric fields but anything that's a legal json property name but not a legal typescript interface field name. I'm running into this a lot trying to tsify a language library written in rust, which exposes syntax tree functionality.

For example, properties with these names need to be quoted too:

  • !
  • !=
  • ==
  • <=
  • >=
  • and lots more

I think the linked PR satisfies all my requirements though, it'd be great if we could get that merged

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