csharp-models-to-typescript icon indicating copy to clipboard operation
csharp-models-to-typescript copied to clipboard

Enum offsets aren't converted correctly

Open bchavez opened this issue 6 years ago • 0 comments

Hey there,

I think I found a bug.

Consider the following C#:

public enum BillingCycle
{
   Yearly = 7,
   Monthly,
   Never = 4
}

If no explicit value is defined for an enum field, the C# compiler will increment the previous field value by +1. The C# compiler actually generates the above enum as:

public enum BillingCycle
{
    Yearly = 7,
    Monthly = 8,
    Never = 4
}

You can test that here: https://sharplab.io/#v2:CYLg1APgAgzABAUwHYFcC2cBCBLANr7JAcwGEBPAY1wQFgAoAb3rhYE0EBDAJ1zLgF44AdgA0zFgFkA9kgAuAC15i6LOADkEANwRcBcACz0AvkA=

The csharp-models-to-typescript will generate the incorrect enum mapping as follows:

export enum BillingCycle {
    Yearly = 7,
    Monthly = 1,
    Never = 4,
}

Version Info: "csharp-models-to-typescript": "^0.16.0"

bchavez avatar Aug 11 '19 18:08 bchavez