import { type Err, type Result } from './utils.js'; export interface DecodeContext { coerceToString?: Coercer; coerceToNumber?: Coercer; coerceToBoolean?: Coercer; coerceToDate?: Coercer; coerceToBigInt?: Coercer; coerceToArray?: (value: unknown) => unknown; acceptNaN?: boolean; unknownFields?: 'reject' | 'drop' | 'discard'; } export interface DecoderOpts extends DecodeContext { coerceNumberToString?: boolean; coerceNumberToBoolean?: boolean; coerceStringToNumber?: boolean; coerceScalar?: boolean; coerceStringToDate?: boolean; coerceNumberToDate?: boolean; coerceDate?: boolean; coerceAll?: boolean; coerceStringToBigInt?: boolean; coerceNumberToBigInt?: boolean; coerceBigInt?: boolean; } export type Coercer = (value: unknown) => Result; export type Validator = (value: T) => Result; export type AsyncValidator = (value: T) => Result | Promise>; export declare function runCoercer(coercer: Coercer, u: unknown): Result; export declare abstract class Type { abstract print(): string; abstract decode(u: unknown, opts: DecodeContext): Result; abstract validate(v: T, opts: DecodeContext): Promise>; abstract validateSync(v: T, opts: DecodeContext): Result; validators?: Validator[]; asyncValidators?: AsyncValidator[]; addValidator(validator: Validator): this; addAsyncValidator(validator: AsyncValidator): this; validateBase(v: T, _opts: DecodeContext): Promise>; protected checkSync(): void; validateBaseSync(v: T, _opts: DecodeContext): Result; default(value: DefaultValue): Type; optional(): OptionalType; nullable(): NullableType; deepMap(_fn: (t: Type) => Type): Type; } export declare function copyValidators>(src: Type, dst: D): D; export declare class AsyncValidatorError extends Error { readonly type: Type; constructor(type: Type); } export type TypeOf = D extends { decode: (u: unknown, opts: DecodeContext) => Result; } ? T : never; export type RTError = { path: string[]; error: string; }[]; export declare function decode(type: Type, value: unknown, opts?: DecoderOpts): Result; export declare function validate(type: Type, value: unknown, opts?: DecoderOpts): Promise>; export declare function validateSync(type: Type, value: unknown, opts?: DecoderOpts): Result; export declare function error(error: string, path?: string[]): Err; export declare function resolveContext(opts: DecoderOpts): DecodeContext; export type DefaultValue = T extends object ? () => T : T | (() => T); export declare class DefaultType extends Type { type: Type; defaultValue: T | (() => T); constructor(type: Type, defaultValue: DefaultValue); private getDefault; print(): string; decode(u: unknown, opts: DecodeContext): Result; validate(v: T, opts: DecodeContext): Promise>; validateSync(v: T, opts: DecodeContext): Result; } export declare class OptionalType extends Type { type: Type; constructor(type: Type); print(): string; decode(u: unknown, opts: DecodeContext): Result; validate(v: T | undefined, opts: DecodeContext): Promise>; validateSync(v: T | undefined, opts: DecodeContext): Result; } export declare class NullableType extends Type { type: Type; constructor(type: Type); print(): string; decode(u: unknown, opts: DecodeContext): Result; validate(v: T | null | undefined, opts: DecodeContext): Promise>; validateSync(v: T | null | undefined, opts: DecodeContext): Result; } export declare function acceptsUndefined(type: Type): boolean; export declare function withDefault(type: Type, defaultValue: DefaultValue): DefaultType; export declare function optional(type: Type): OptionalType; export declare function nullable(type: Type): NullableType;