UNPKG

1.39 kBTypeScriptView Raw
1import type { BasePredicate } from '../index.js';
2export type Shape = {
3 [key: string]: BasePredicate | Shape;
4};
5/**
6Extracts a regular type from a shape definition.
7
8@example
9```
10const myShape = {
11 foo: ow.string,
12 bar: {
13 baz: ow.boolean
14 }
15}
16
17type X = TypeOfShape<typeof myShape> // {foo: string; bar: {baz: boolean}}
18```
19
20This is used in the `ow.object.partialShape(…)` and `ow.object.exactShape(…)` functions.
21*/
22export type TypeOfShape<S extends BasePredicate | Shape> = S extends BasePredicate<infer X> ? X extends object ? X : never : S extends Shape ? {
23 [K in keyof S]: TypeOfShape<S[K]>;
24} extends object ? {
25 [K in keyof S]: TypeOfShape<S[K]>;
26} : never : never;
27/**
28Test if the `object` matches the `shape` partially.
29
30@hidden
31
32@param object - Object to test against the provided shape.
33@param shape - Shape to test the object against.
34@param parent - Name of the parent property.
35*/
36export declare function partial(object: Record<string, any>, shape: Shape, parent?: string): boolean | string;
37/**
38Test if the `object` matches the `shape` exactly.
39
40@hidden
41
42@param object - Object to test against the provided shape.
43@param shape - Shape to test the object against.
44@param parent - Name of the parent property.
45*/
46export declare function exact(object: Record<string, any>, shape: Shape, parent?: string, isArray?: boolean): boolean | string;