UNPKG

1.86 kBTypeScriptView Raw
1/**
2 * `StructError` objects are thrown (or returned) by Superstruct when its
3 * validation fails. The error represents the first error encountered during
4 * validation. But they also have an `error.failures` property that holds
5 * information for all of the failures encountered.
6 */
7export declare class StructError extends TypeError {
8 branch: Branch;
9 failures: Failure[];
10 path: Path;
11 type: string | undefined;
12 value: any;
13 [key: string]: any;
14 constructor(failures: Failure[]);
15}
16/**
17 * `Path` arrays specify a nested value's location in a root object or array.
18 *
19 * ```js
20 * ['user', 'address', 'city']
21 * ['nodes', 1, 'nodes', 0, 'text']
22 * ```
23 */
24export declare type Path = Array<number | string>;
25/**
26 * `Branch` arrays contain each value following a path down from the root.
27 *
28 * ```js
29 * [root, ..., parent, value]
30 * ```
31 */
32export declare type Branch = Array<any>;
33/**
34 * `Failure` objects represent a specific failure in validation. They are plain
35 * objects that can be turned into real `StructError` when needed.
36 *
37 * ```js
38 * {
39 * type: 'number',
40 * value: 'invalid',
41 * path: [1],
42 * branch: [
43 * [1, 'invalid', 2],
44 * 'invalid',
45 * ]
46 * }
47 */
48export declare type Failure = {
49 /**
50 * The branch of values following a path down from the root.
51 */
52 branch: Branch;
53 /**
54 * The path of indices to retrieve the failing value from the root.
55 */
56 path: Path;
57 /**
58 * The failing value.
59 */
60 value: any;
61 /**
62 * The expected type description of the failing value, or `undefined` if it
63 * didn't have an expected type.
64 */
65 type: string | undefined;
66 /**
67 * Failures can also be augmented with any of your on custom properties.
68 */
69 [key: string]: any;
70};