• Create a TypeScript style enum class which is a mapping that maps from the key -> value and the value -> key. This is effectively the same as defining a non-constant enum, but this only repeats the "Name" of the enum value once.

    Type Parameters

    • E

      Identifies the const enum type being mapped

    Parameters

    • values: {
          [key in string | number | symbol]: E[keyof E]
      }

      The values to populate on the new object

    Returns EnumCls<E>

    A new frozen (immutable) object which looks and acts like a TypeScript Enum class.

    Example

    const enum Animal {
    Dog = 0,
    Cat = 1,
    Butterfly = 2,
    Bear = 3
    }
    const Animals = createEnum<typeof Animal>({
    Dog: Animal.Dog,
    Cat: Animal.Cat,
    Butterfly: Animal.Butterfly,
    Bear: Animal.Bear
    });
    // You end up with an object that maps everything to the name
    Animals.Dog === 0; // true
    Animals[0] === "Dog"; // true
    Animals["Dog"] === 0; // true
    Animals.Cat === 1; // true
    Animals[1] === "Cat"; // true
    Animals["Cat"] === 1; // true