Skip to content

[Feature Request] Add "preserveConstEnums" option to transform-typescript #6476

@ForbesLindesay

Description

@ForbesLindesay

When using the typescript compiler, there is an option to "preserve const enums", which essentially just treats const enums exactly the same as non-const enums. It would be really useful to have the same feature in the babel transform.

Input Code

export const enum E {
    A = 1
}

Babel Configuration (.babelrc, package.json, cli command)

{
  "plugins": [
    ["transform-typescript", {"preserveConstEnums": true}]
  ]
}

Expected Behavior

export let E;

(function (E) {
  E[E["A"] = 1] = "A";
})(E || (E = {}));

Current Behavior

Throws: 'const' enums are not supported

Possible Solution

Add an option that makes const enums behave exactly the same as regular enums.

Context

I want to be able to use babel to transform my typescript in development, as this will be much faster than doing a babel pass and a typescript pass, and babel is needed for other plugins. In production, I can use the slower typescript transform, which handles const enums properly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: typescriptoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions