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"
}
v5.2 now defaults to string enums
http://docs.servicestack.net/releases/v5.2#typescript
-
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.