UNPKG

2.3 kBTypeScriptView Raw
1/**
2 * A detailed object enumerating where the validation failed exactly.
3 */
4export declare type Details = (string | Details)[] | {
5 [key in string | number | symbol]: string | Details;
6};
7/**
8 * A predefined error code indicating what type of failure has occured.
9 */
10export declare type Failcode = typeof Failcode[keyof typeof Failcode];
11export declare const Failcode: {
12 /** The type of the received primitive value is incompatible with expected one. */
13 readonly TYPE_INCORRECT: "TYPE_INCORRECT";
14 /** The received primitive value is incorrect. */
15 readonly VALUE_INCORRECT: "VALUE_INCORRECT";
16 /** The key of the property is incorrect. */
17 readonly KEY_INCORRECT: "KEY_INCORRECT";
18 /** One or more elements or properties of the received object are incorrect. */
19 readonly CONTENT_INCORRECT: "CONTENT_INCORRECT";
20 /** One or more arguments passed to the function is incorrect. */
21 readonly ARGUMENT_INCORRECT: "ARGUMENT_INCORRECT";
22 /** The value returned by the function is incorrect. */
23 readonly RETURN_INCORRECT: "RETURN_INCORRECT";
24 /** The received value does not fulfill the constraint. */
25 readonly CONSTRAINT_FAILED: "CONSTRAINT_FAILED";
26 /** The property must be present but missing. */
27 readonly PROPERTY_MISSING: "PROPERTY_MISSING";
28 /** The property must not be present but present. */
29 readonly PROPERTY_PRESENT: "PROPERTY_PRESENT";
30 /** The value must not be present but present. */
31 readonly NOTHING_EXPECTED: "NOTHING_EXPECTED";
32};
33/**
34 * A successful validation result.
35 */
36export declare type Success<T> = {
37 /**
38 * A tag indicating success.
39 */
40 success: true;
41 /**
42 * The original value, cast to its validated type.
43 */
44 value: T;
45};
46/**
47 * A failed validation result.
48 */
49export declare type Failure = {
50 /**
51 * A tag indicating failure.
52 */
53 success: false;
54 /**
55 * An error code assigned to this type of error.
56 */
57 code: Failcode;
58 /**
59 * A message indicating the reason why the validation failed.
60 */
61 message: string;
62 /**
63 * A detailed object enumerating where the validation failed exactly.
64 */
65 details?: Details;
66};
67/**
68 * The result of a type validation.
69 */
70export declare type Result<T> = Success<T> | Failure;