declare const TYPE: unique symbol; /** A schema built by `oneOf`, `listOf`, `setOf`, `recordOf`, `nullable` or `type`. */ export interface Shaped { readonly schema: "oneOf" | "list" | "set" | "record" | "nullable" | "type"; /** Phantom: the type it describes. */ readonly [TYPE]?: T; } /** A schema: a constructor, a nested object of schemas, or one built by the functions below. */ export type Schema = StringConstructor | NumberConstructor | BooleanConstructor | Shaped | { readonly [field: string]: Schema; }; /** An object of field schemas: a payload's schema. */ export type Fields = { readonly [field: string]: Schema; }; /** The type a schema describes. */ export type TypeOf = S extends StringConstructor ? string : S extends NumberConstructor ? number : S extends BooleanConstructor ? boolean : S extends Shaped ? T : S extends { readonly [field: string]: Schema; } ? { -readonly [K in keyof S]: TypeOf; } : never; interface OneOf extends Shaped { readonly schema: "oneOf"; readonly values: readonly T[]; } interface Of extends Shaped { readonly schema: "list" | "set" | "record" | "nullable"; readonly of: Schema; } /** One of these values: `oneOf("yes", "no")` is `"yes" | "no"`. */ export declare function oneOf(...values: T[]): OneOf; /** A list: `listOf(String)` is `string[]`. */ export declare function listOf(item: S): Of[]>; /** A set: `setOf(String)` is `Set`. */ export declare function setOf(item: S): Of>>; /** A record keyed by strings: `recordOf(Number)` is `Record`. */ export declare function recordOf(value: S): Of>>; /** The schema's type, or null. */ export declare function nullable(of: S): Of | null>; /** Any TypeScript type, for what a schema can't say. It is not checked at run time. */ export declare function type(): Shaped; export declare function isSchema(value: unknown): value is Schema; /** * Where `value` doesn't match `schema`, in words ("payment: 1, but its schema says string"), * or null when it matches. Objects must have exactly their schema's fields. */ export declare function mismatch(schema: Schema, value: unknown, path?: string): string | null; /** A schema in words, for the views: `{ socket: number, chains: string[] }`. */ export declare function describeSchema(schema: Schema): string; export {};