ts-rs icon indicating copy to clipboard operation
ts-rs copied to clipboard

Is it possible to generate numeric enums?

Open ottosson opened this issue 2 years ago • 9 comments

Hi. thanks for this awesome library!

Is it possible to generate numeric enums in typescript from my rust enums?

#[derive(Serialize, Deserialize, TS, Debug)]
#[serde(rename_all = "camelCase")]
#[ts(export, export_to = "../src/types/interfaces/")]
pub enum PlotType {
  Display = 0,
  Extents = 1,
  Limits = 2,
  View = 3,
  Window = 4,
  Layout = 5,
}

becomes

export type PlotType = "display" | "extents" | "limits" | "view" | "window" | "layout";

I would expect it to become something like

export const enum PlotType = {
  Display = 0,
  Extents = 1,
  Limits = 2,
  View = 3,
  Window = 4,
  Layout = 5,
}

Is this possible?

ottosson avatar Feb 06 '23 21:02 ottosson