Skip to content

[Feature Request] TypeScript make generated codes from enum could be minified when not used #9268

@morlay

Description

@morlay

Feature Request

Is your feature request related to a problem? Please describe.

For now TypeScript will transform enum from

enum Test {
    Key = 1
}

to

var Test;
(function (Test) {
    Test[Test["Key"] = 1] = "Key";
})(Test || (Test = {}));

This result is not friendly for uglyify or tree-shaking.
When Test is not be used, the generated code block always remain as dead codes.

Describe the solution you'd like

prefer to generate codes below:

var Test = /*#__PURE__*/(function () {
    var e = {}
    e[e["Key"] = 1] = "Key";
    return e
})();

image

The suggestion version will be removed.

related: microsoft/TypeScript#27604
custom plugin: https://github.com/morlay/babel-plugin-typescript-iife-enum

Metadata

Metadata

Assignees

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