Skip to content

Feature request: #[ts(repr(enum)) enhancement #449

@eythaann

Description

@eythaann

#[ts(repr(enum)) was a good addition to the project on last version, but when using #[ts(repr(enum = name)) and serde rename it takes the renamed value as key and as value, I think the key should be the same as used on Rust side and only change the value.

This is a quality of life, as the enum usage and values will be the same on rust and ts sides.

Example:

#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema, TS)]
#[serde(rename_all = "kebab-case")]
#[ts(repr(enum = name))]
pub enum MixBlendMode {
    Normal,
    #[default]
    Multiply,
    Screen,
    Overlay,
    Darken,
    Lighten,
    ColorDodge,
    ColorBurn,
    HardLight,
    SoftLight,
    Difference,
    Exclusion,
    Hue,
    Saturation,
    Color,
    Luminosity,
    PlusDarker,
    PlusLighter,
}

Current Behavior:

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

export enum MixBlendMode {
  "normal" = "normal",
  "multiply" = "multiply",
  "screen" = "screen",
  "overlay" = "overlay",
  "darken" = "darken",
  "lighten" = "lighten",
  "color-dodge" = "color-dodge",
  "color-burn" = "color-burn",
  "hard-light" = "hard-light",
  "soft-light" = "soft-light",
  "difference" = "difference",
  "exclusion" = "exclusion",
  "hue" = "hue",
  "saturation" = "saturation",
  "color" = "color",
  "luminosity" = "luminosity",
  "plus-darker" = "plus-darker",
  "plus-lighter" = "plus-lighter",
}

Rust: MixBlendMode.ColorDodge
Typescript: MixBlendMode["color-dodge"]

Expected Behavior:

export enum MixBlendMode {
  "Normal" = "normal",
  "Multiply" = "multiply",
  "Screen" = "screen",
  "Overlay" = "overlay",
  "Darken" = "darken",
  "Lighten" = "lighten",
  "ColorDodge" = "color-dodge",
  "ColorBurn" = "color-burn",
  "HardLight" = "hard-light",
  "SoftLight" = "soft-light",
  "Difference" = "difference",
  "Exclusion" = "exclusion",
  "Hue" = "hue",
  "Saturation" = "saturation",
  "Color" = "color",
  "Luminosity" = "luminosity",
  "PlusDarker" = "plus-darker",
  "PlusLighter" = "plus-lighter",
}

Rust: MixBlendMode.ColorDodge
Typescript: MixBlendMode.ColorDodge

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions