Skip to content

[JavaScript] Enums are not exported correctly #2102

@delenius

Description

@delenius

In the generated models, when there are enum, an extra segment is introduced, like

//export module
if ( typeof define === "function" && define.amd ) {
  define('SomeTypeEnum', [], function() {
    return SomeTypeEnum;
  });
}

This has the effect that

  • If the module system is AMD, this will just export the enum, and not the main model class
  • If the module system is not AMD, this will just export the model class, and not the enum

The import/export setup also seems a bit inconsistent and strange in general. We are using both returns and setting the "module" parameter. Shouldn't we be using this UMD template?

I propose that the way we export enums should be as a property of the module class itself. For example, we might have a module Account which includes an enum AccountType. Then, we should export these (using the style in the template I linked to above) using

exports = Account;
exports.AccountType = AccountType;

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions