UNPKG

1.29 kBTypeScriptView Raw
1import { BasePredicate } from '..';
2export interface 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 declare type TypeOfShape<S extends BasePredicate | Shape> = S extends BasePredicate<infer X> ? X : S extends Shape ? {
23 [K in keyof S]: TypeOfShape<S[K]>;
24} : never;
25/**
26Test if the `object` matches the `shape` partially.
27
28@hidden
29
30@param object - Object to test against the provided shape.
31@param shape - Shape to test the object against.
32@param parent - Name of the parent property.
33*/
34export declare function partial(object: Record<string, any>, shape: Shape, parent?: string): boolean | string;
35/**
36Test if the `object` matches the `shape` exactly.
37
38@hidden
39
40@param object - Object to test against the provided shape.
41@param shape - Shape to test the object against.
42@param parent - Name of the parent property.
43*/
44export declare function exact(object: Record<string, any>, shape: Shape, parent?: string, isArray?: boolean): boolean | string;