Skip to content

[JavaScript] Strange enum generation #2101

@delenius

Description

@delenius

It seems that the generation of enums in the JS client generator is a bit odd. Currently, I get something like (omitting comments):

var AccountTypeEnum = function AccountTypeEnum() {
  var self = this;
  self.PAIDACCOUNT = "paidAccount",
  self.FREEACCOUNT = "freeAccount"
}

This is a class, where each instance has its own copy of the fields PAIDACCOUNT and FREEACCOUNT. To use this, you would currently have to do:

var myAccountType = new AccountTypeEnum();
doSomething(myAccountType.PAIDACCOUNT);

This is a strange way to encode enums.

I propose that we change it to just an object,

var AccountTypeEnum = {
  PAIDACCOUNT: "paidAccount",
  FREEACCOUNT: "freeAccount"
}

The usage would then be

doSomething(AccountTypeEnum.PAIDACCOUNT);

If the powers that be agree, I can file a PR.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions