tsify icon indicating copy to clipboard operation
tsify copied to clipboard

Bug: Fields starting with numeric literal need to be quoted

Open Pistonight opened this issue 1 year ago • 1 comments

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 avatar Oct 13 '23 04:10 Pistonight

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

Swolebrain avatar Dec 08 '23 00:12 Swolebrain