Generated enum syntax

Hello,

I’m upgrading an old application (backend and frontend) from ServiceStack 4.0.54 to the latest version and I saw that the syntax for the enums changed. Previously the TypescriptGenerator generated the following code:

    export enum ScheduleMode
    {
        Asap,
        Specified,
    }

And since 4.0.62 it generates the following syntax:

    type ScheduleMode = Asap | Specified;

The new syntax breaks my code that used the enum like so:

if (ScheduleMode[schedule.status] === <any>ScheduleMode.Asap)

Is there a way to get the old syntax back without modifying each of my enumerations ?

Thanks

The old syntax only works when your Enum is serialized as an integer whereas the default serialization for Enum is a string.

You can opt-in to use the old enum syntax by specifying your enum should be serialized as a number, which you can do for all enums with:

JsConfig.TreatEnumAsInteger = true;

Or on select enums by annotating it with the [Flags] attribute:

[Flags]
public class MyEnum { ... }

Thanks for the info, I was able to implement a solution to my issue.