1 | import type { BasePredicate } from '../index.js';
|
2 | export type Shape = {
|
3 | [key: string]: BasePredicate | Shape;
|
4 | };
|
5 | /**
|
6 | Extracts a regular type from a shape definition.
|
7 |
|
8 | @example
|
9 | ```
|
10 | const myShape = {
|
11 | foo: ow.string,
|
12 | bar: {
|
13 | baz: ow.boolean
|
14 | }
|
15 | }
|
16 |
|
17 | type X = TypeOfShape<typeof myShape> // {foo: string; bar: {baz: boolean}}
|
18 | ```
|
19 |
|
20 | This is used in the `ow.object.partialShape(…)` and `ow.object.exactShape(…)` functions.
|
21 | */
|
22 | export 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 | /**
|
28 | Test 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 | */
|
36 | export declare function partial(object: Record<string, any>, shape: Shape, parent?: string): boolean | string;
|
37 | /**
|
38 | Test 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 | */
|
46 | export declare function exact(object: Record<string, any>, shape: Shape, parent?: string, isArray?: boolean): boolean | string;
|