object-shape-tester
Version:
Test object properties and value types.
55 lines (54 loc) • 1.6 kB
TypeScript
import { type IsEqual } from 'type-fest';
import { type Shape, type ShapeInitType } from '../shape/shape.js';
/**
* Kind for {@link recordShape}.
*
* @category Internal
*/
export declare const recordShapeKind: "recordShape";
/**
* Creates a shape that requires an object with certain keys and values.
*
* @category Shape
* @example
*
* ```ts
* import {recordShape, checkValidShape} from 'object-shape-tester';
*
* const myShape = recordShape({
* keys: '',
* values: -1,
* });
*
* checkValidShape({a: 0}, myShape); // `true`
* checkValidShape({a: '0'}, myShape); // `false`
* ```
*/
export declare function recordShape<K, V, IsPartial extends boolean>({ keys, values, partial, additionalProperties, }: {
keys: K;
values: V;
/**
* If set to `true`, all keys are optional.
*
* @default false
*/
partial?: IsPartial;
/**
* Set to `true` to allow additional properties in addition to the required properties.
*
* @default false
*/
additionalProperties?: boolean;
}): import("@sinclair/typebox").TUnsafe<IsEqual<IsPartial, true> extends true ? Partial<Record<Extract<ShapeInitType<K>, PropertyKey>, ShapeInitType<V>>> : Record<Extract<ShapeInitType<K>, PropertyKey>, ShapeInitType<V>>>;
/**
* Converts a keys requirement to a {@link Shape}.
*
* @category Internal
*/
export declare function defineKeysShape(keys: unknown): Shape;
/**
* Extracts all finite keys, if any, that match the given keys {@link Shape}.
*
* @category Internal
*/
export declare function extractFiniteKeys(keys: Shape): unknown[];