Skip to content

Default value for an Enum is a number when enumStringInitializers is true #204

Description

@martiendejong

I created a class in C# that uses an enum in it. I want to convert the enum values to strings in my typescript class. I am also using a default value. In the genreated typescript enum the values are converted to strings, but in my ts class the value is still a number. the typescript code won't compile unless the enum default value is a string on the class that uses it as well.

My C# class:

public class OrganizationUser
{
// other properties

public UserOrganizationRole Relation { get; set; } = UserOrganizationRole.Viewer;

}

C# enum:

[TsStringInitializers]
public enum UserOrganizationRole
{
// other values
Viewer,
}

tgconfig.json:

{
"singleQuotes": true,
"csNullableTranslation": "null|undefined",
"outputPath": "../frontend",
"camelCase": true,
"enumStringInitializers": true
}

user-organization-role.ts

export enum UserOrganizationRole {
// other values
Viewer = 'Viewer',
}

organization-user.ts

export class OrganizationUser {
// other properties
relation: string = 'Viewer';
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions