pokemon-rogue-battle
    Preparing search index...

    Function enumValueToKey

    • Return the name of the key that matches the given Enum value. Can be used to emulate Typescript reverse mapping for const objects or string enums.

      Type Parameters

      Parameters

      Returns InferKeys<T, V>

      The name of the key with the specified value

      const thing = {
      one: 1,
      two: 2,
      } as const;
      console.log(enumValueToKey(thing, 2)); // output: "two"

      Error if an invalid enum value is passed to the function

      If multiple keys map to the same value, the first one (in insertion order) will be retrieved, but the return type will be the union of ALL their corresponding keys.