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

    Function recordShape

    • Creates a shape that requires an object with certain keys and values.

      Type Parameters

      • K
      • V
      • IsPartial extends boolean

      Parameters

      • __namedParameters: { additionalProperties?: boolean; keys: K; partial?: IsPartial; values: V }
        • OptionaladditionalProperties?: boolean

          Set to true to allow additional properties in addition to the required properties.

          false
          
        • keys: K
        • Optionalpartial?: IsPartial

          If set to true, all keys are optional.

          false
          
        • values: V

      Returns TUnsafe<
          IsEqual<IsPartial, true> extends true
              ? Partial<
                  Record<Extract<ShapeInitType<K>, PropertyKey>, ShapeInitType<V>>,
              >
              : Record<Extract<ShapeInitType<K>, PropertyKey>, ShapeInitType<V>>,
      >

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

      const myShape = recordShape({
      keys: '',
      values: -1,
      });

      checkValidShape({a: 0}, myShape); // `true`
      checkValidShape({a: '0'}, myShape); // `false`