object-shape-tester - v6.3.3
    Preparing search index...

    Function enumShape

    • Creates a shape that requires matching a value within the given enum.

      Type Parameters

      • const EnumObject extends Record<string, string | number>

      Parameters

      • enumObject: EnumObject
      • OptionaldefaultValue: Values<EnumObject>

        If omitted or undefined, the first value in the enum object will be used as the default.

      Returns Shape<TUnion<ShapeInitSchema<TConst<Values<EnumObject>>>[]>>

      import {enumShape, checkValidShape} from 'object-shape-tester';

      enum MyEnum {
      A = 'a',
      B = 'b',
      }

      const myShape = enumShape(MyEnum);

      checkValidShape(MyEnum.A, myShape); // `true`
      checkValidShape('a', myShape); // `true`
      checkValidShape('c', myShape); // `false`