Skip to content

[Bug]: Enum string value gets reverse mapped #14402

@MPuida

Description

@MPuida

💻

  • Would you like to work on a fix?

How are you using Babel?

Other (Next.js, Gatsby, vue-cli, ...)

Input code

enum Enum {
    A,
    B = "B",
    C = 4
}

enum Test1 {
    A1 = Enum.A,
    B1 = Enum.B,
    C1 = Enum.C
}

enum Test2 {
    A1,
    B1 = "B",
    C1 = 4
}


describe("Match Enums", () => {
    it("Matches", () => {
        expect(Test1).toEqual(Test2);
    });
});

Configuration file name

babel.config.js

Configuration

module.exports = {
    presets: [["@babel/preset-env", { targets: { node: "current" }}], "@babel/preset-react", "@babel/preset-typescript"]
};

Current and expected behavior

Current behavior: Test1 and Test2 does not match due to an additional key ("B") in Test1 enum. If the key "B1" in Test1 is renamed and matches the value, enums match as expected.

Expected behavior: Enum values which are a type of string should not have reverse mapping.

Environment

  • Babel version: [^6.23.0]
  • Node version: [v14.16.0]
  • npm/Yarn version: [npm v6.14.15/Yarn 3.0.2]
  • TypeScript version: [^4.4.3]
  • OS: [Windows 10]

Possible solution

No response

Additional context

Screenshot of the test result:

image

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