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
Sign in
Password icon
Signed in as (Sign out)
You have left! (?) (thinking…)
Sam Bosell shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →


Sign in
Password icon
Signed in as (Sign out)
  • Alex commented  ·   ·  Flag as inappropriate

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

  • Sam Bosell commented  ·   ·  Flag as inappropriate

    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")]

    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