enumReverseMap | WebHare Platform SDK
WebHare Platform SDK
    Preparing search index...

    Function enumReverseMap

    • Returns the reverse mapping of a value of an const object used as enum. Can only be used for numbers.

      Type Parameters

      • const T extends Record<string, string | number>
      • const V extends number

      Parameters

      • enumObj: T

        The enum object to reverse map.

      • value: V

        The value to look up in the reverse map.

      Returns EnumEntries<T, V, keyof T>[0]

      The key corresponding to the given value in the enum object.

      const Color = {
      Red: 1,
      Green: 2,
      Blue: 3
      } as const;
      const key = enumReverseMap(Color, 2); // "Green"