I suggest you ...

Enum Serialization and Typescript String Enums

I understand if this is changed it may break projects based on Typescript < 2.4. I propose a new flag or option to serialize enum strings as enum strings instead of string literals. This would minimally allow us to get access to the list of strings available for an enum which is not readily available with a string Literal.

Instead of this:

export type MessagePriority = "Normal" | "Low" | "High";

It would be:

export enum MessagePriority{
Normal = "Normal",
Low = "Low",
High = "High"
}

13 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    Sam Bosell shared this idea  ·   ·  Admin →

    2 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      Signed in as (Sign out)
      Submitting...
      • Alex commented  · 

        Would appreciate this, even as a flag for the client generator.

      • Sam Bosell commented  · 

        I would just add that allowing for options like creating an object instead of a typescript enum would also be helpful for also serializing description attributes. Ideally this would be nice:

        Enum MessagePriority {
        [Description("My description")]
        Normal=1,
        High=2
        }

        MessagePriority = [{ key: "Normal", value: 1, description: "My description attribute"},{ key: "High", value: 2, description: ""}]

        Main use case is populating drop down lists or anything on the UI that needs to display these lists.

      Feedback and Knowledge Base