A new frozen (immutable) object which looks and acts like a TypeScript Enum class.
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
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.