Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
martiendejong opened this issue Aug 15, 2024 · 0 comments

Comments

@martiendejong
Copy link

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';
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant