isguard-ts
    Preparing search index...

    Function isEnum

    • Creates an EnumTypeGuard that checks that the value is a valid enum value.

      Type Parameters

      • T extends Readonly<Record<string, string | number>>

        The enum type

      Parameters

      • enumObj: T

        The enum object to create a guard for

      Returns EnumTypeGuard<T>

      A type guard for values of T (T[keyof T])

      enum Direction {
      up = 0,
      down = 1,
      left = 2,
      right = 3,
      }

      const isDirection = isEnum(Direction);

      isDirection(Direction.up); // true
      isDirection(2); // true
      isDirection("hello"); // false