declare const keySignature: unique symbol; export { keySignature }; declare const typeErrSym: unique symbol; declare const coercionTypeSymbol: unique symbol; export declare abstract class Type { [typeErrSym]?: string | (() => string); [coercionTypeSymbol]?: boolean; constructor(); abstract parse(value: unknown): T; abstract and(schema: K): any; or(schema: K): UnionType<[this, K]>; optional(this: NullableType): OptionalType; optional(this: OptionalType): this; optional(): OptionalType; nullable(this: OptionalType): NullableType; nullable(this: NullableType): this; nullable(): NullableType; try(value: unknown): T | ValidationError; map(fn: (value: T) => K): MappedType; onTypeError(msg: string | (() => string)): this; protected typeError(msg: string): ValidationError; } export type MappedType = Type & { withPredicate: (fn: Predicate['func'], errMsg?: ErrMsg) => Type & MappedType; default: (value: T | (() => T)) => Type & MappedType; }; declare class MTypeClass extends Type implements WithPredicate, Defaultable { protected schema: T; protected mapFn: (value: Infer) => K; private predicates; private defaultValue?; constructor(schema: T, mapFn: (value: Infer) => K); parse(value: unknown): K; and(other: O): never; withPredicate(fn: Predicate['func'], errMsg?: ErrMsg): MTypeClass; default(value: K | (() => K)): MTypeClass; } export declare class ValidationError extends Error { name: string; path?: (string | number)[]; collectedErrors?: Record; constructor(message: string, path?: (string | number)[], collectedErrors?: Record); } export type Eval = T extends any[] | Date | unknown ? T : Flat; export type AnyType = Type; export type Infer = T extends AnyType ? (T extends Type ? K : any) : T; declare const allowUnknownSymbol: unique symbol; declare const shapekeysSymbol: unique symbol; type ObjectIntersection, O2 extends ObjectType> = O1 extends ObjectType ? O2 extends ObjectType ? ObjectType extends infer T extends ObjectShape ? Flat : never> : never : never; type ArrayIntersectionObj, A2 extends ArrayType> = A1 extends ArrayType ? A2 extends ArrayType ? IntersectionResult : never : never; type ArrayIntersection, A2 extends ArrayType> = ArrayType>; type TupleIntersection, T2 extends TupleType> = T1 extends TupleType ? T2 extends TupleType ? TupleType> : never : never; export type IntersectionResult = T extends ObjectType ? K extends ObjectType ? ObjectIntersection ? X : never, K extends infer X extends ObjectType ? X : never> : IntersectionType ? X : never, K> : T extends ArrayType ? K extends ArrayType ? ArrayIntersection : IntersectionType : T extends TupleType ? K extends TupleType ? TupleIntersection : IntersectionType : T extends MTypeClass ? never : K extends MTypeClass ? never : IntersectionType; type ErrMsg = string | ((value: T) => string); type Predicate = { func: (value: T) => boolean; errMsg?: ErrMsg; }; interface WithPredicate { withPredicate(fn: Predicate['func'], errMsg?: ErrMsg): any; } interface Defaultable { default(value: T | (() => T)): any; } export type StringOptions = { min?: number; max?: number; pattern?: RegExp; valid?: string[]; predicate?: Predicate['func'] | Predicate | Predicate[]; default?: string | (() => string); }; export declare class StringType extends Type implements WithPredicate, Defaultable { private predicates; private defaultValue?; constructor(opts?: StringOptions); parse(value?: unknown): string; and(schema: K): IntersectionType; pattern(regexp: RegExp, errMsg?: ErrMsg): StringType; min(x: number, errMsg?: ErrMsg): StringType; max(x: number, errMsg?: ErrMsg): StringType; valid(list: string[], errMsg?: ErrMsg): StringType; withPredicate(fn: Predicate['func'], errMsg?: ErrMsg): StringType; default(value: string | (() => string)): StringType; } export declare class BooleanType extends Type implements Defaultable { private defaultValue?; constructor(defaultValue?: boolean | (() => boolean) | undefined); parse(value?: unknown): boolean; and(schema: K): IntersectionType; default(value: boolean | (() => boolean)): BooleanType; } export type NumberOptions = { min?: number; max?: number; coerce?: boolean; predicate?: Predicate['func'] | Predicate | Predicate[]; default?: number | (() => number); }; export declare class NumberType extends Type implements WithPredicate, Defaultable { private predicates; private defaultValue?; private coerceFlag?; constructor(opts?: NumberOptions); parse(value?: unknown): number; and(schema: K): IntersectionType; min(x: number, errMsg?: ErrMsg): NumberType; max(x: number, errMsg?: ErrMsg): NumberType; coerce(value?: boolean): NumberType; withPredicate(fn: Predicate['func'], errMsg?: ErrMsg): NumberType; default(value: number | (() => number)): NumberType; } export type BigIntOptions = { min?: number | bigint; max?: number | bigint; predicate?: Predicate['func'] | Predicate | Predicate[]; default?: bigint | (() => bigint); }; export declare class BigIntType extends Type implements WithPredicate, Defaultable { private readonly predicates; private readonly defaultValue?; constructor(opts?: BigIntOptions); parse(value?: unknown): bigint; and(schema: K): IntersectionType; min(x: number | bigint, errMsg?: ErrMsg): BigIntType; max(x: number | bigint, errMsg?: ErrMsg): BigIntType; withPredicate(fn: Predicate['func'], errMsg?: ErrMsg): BigIntType; default(value: bigint | (() => bigint)): BigIntType; } export declare class UndefinedType extends Type { parse(value: unknown): undefined; and(schema: K): IntersectionType; } export declare class NullType extends Type implements Defaultable { private defaultValue; constructor(); parse(value?: unknown): null; and(schema: K): IntersectionType; default(): NullType; } export type Literal = string | number | boolean | undefined | null; export declare class LiteralType extends Type implements Defaultable { private readonly literal; private readonly defaultValue?; constructor(literal: T); parse(value?: unknown): T; and(schema: K): IntersectionType; default(): LiteralType; } export declare class UnknownType extends Type implements Defaultable { private readonly defaultValue?; constructor(); parse(value?: unknown): unknown; and(schema: K): IntersectionType; default(value: any | (() => any)): any; } export declare class OptionalType extends Type | undefined> { readonly schema: T; constructor(schema: T); parse(value: unknown, opts?: any): Infer | undefined; required(): T; and(schema: K): IntersectionType; } type Nullable = T | null; export declare class NullableType extends Type | null> implements Defaultable | null> { readonly schema: T; private readonly defaultValue?; constructor(schema: T); parse(value?: unknown): Infer | null; and(schema: K): IntersectionType; required(): T; default(value: Nullable> | (() => Nullable>)): any; } export type DateOptions = { predicate?: Predicate['func'] | Predicate | Predicate[]; default?: Date | (() => Date); }; export declare class DateType extends Type implements WithPredicate, Defaultable { private readonly predicates; private readonly defaultValue?; constructor(opts?: DateOptions); parse(value?: unknown): Date; and(schema: K): IntersectionType; withPredicate(fn: Predicate['func'], errMsg?: ErrMsg): DateType; default(value: Date | (() => Date)): DateType; private stringToDate; private assertDate; } export type ObjectShape = { [key: string]: AnyType; [keySignature]?: AnyType; }; type OptionalKeys = { [key in keyof T]: undefined extends Infer ? (key extends symbol ? never : key) : never; }[keyof T]; type RequiredKeys = Exclude>; type InferKeySignature = T extends { [keySignature]: AnyType; } ? T extends { [keySignature]: infer KeySig; } ? KeySig extends AnyType ? { [key: string]: Infer; } : {} : {} : {}; type Flat = T extends {} ? (T extends Date ? T : { [key in keyof T]: T[key]; }) : T; type InferObjectShape = Flat & { [key in OptionalKeys]?: T[key] extends Type ? K : any; } & { [key in RequiredKeys]: T[key] extends Type ? K : any; }>>; export type ToUnion = T[number]; export type PartialShape = { [key in keyof T]: T[key] extends OptionalType ? T[key] : OptionalType; }; export type DeepPartialShape = { [key in keyof T]: T[key] extends ObjectType ? OptionalType>> : T[key] extends OptionalType ? T[key] : OptionalType; }; type MergeShapes = { [key in keyof (T & K)]: key extends keyof T ? key extends keyof K ? IntersectionResult : T[key] : key extends keyof K ? K[key] : never; }; export type StringTypes = T extends string ? T : never; export type PathOptions = { suppressPathErrMsg?: boolean; }; export type ObjectOptions = { allowUnknown?: boolean; predicate?: Predicate>['func'] | Predicate> | Predicate>[]; default?: InferObjectShape | (() => InferObjectShape); collectErrors?: boolean; }; export declare class ObjectType extends Type> implements WithPredicate>, Defaultable> { private readonly objectShape; private readonly predicates; private readonly defaultValue?; [allowUnknownSymbol]: boolean; [shapekeysSymbol]: string[]; [coercionTypeSymbol]: boolean; [keySignature]: AnyType | undefined; private shouldCollectErrors; private _parse; constructor(objectShape: T, opts?: ObjectOptions); parse(value?: unknown, parseOpts?: ObjectOptions & PathOptions): InferObjectShape; private buildPathError; private selectParser; private parseObject; private parseObjectCollect; private parseObjectConv; private parseObjectConvCollect; private parseRecord; private parseRecordCollect; private parseRecordConv; private parseRecordConvCollect; private parseMixRecord; private parseMixRecordCollect; private parseMixRecordConv; private parseMixRecordConvCollect; and(schema: K): IntersectionResult; pick>(keys: K[], opts?: ObjectOptions, ToUnion>> & (T extends { [keySignature]: AnyType; } ? T extends { [keySignature]: infer KeySig; } ? { [key in Exclude, keyof T>]: KeySig; } : {} : {})>>): ObjectType, ToUnion>> & (T extends { [keySignature]: AnyType; } ? T extends { [keySignature]: infer KeySig; } ? { [key in Exclude, keyof T>]: KeySig; } : {} : {})>>; omit>(keys: K[], opts?: ObjectOptions>>>): ObjectType>>>; partial>> & { deep: true; }>(opts: K): ObjectType>>; partial>> & PartialOpts>(opts?: K): ObjectType>>; shape(): T; withPredicate(fn: Predicate>['func'], errMsg?: ErrMsg>): ObjectType; default(value: InferObjectShape | (() => InferObjectShape)): ObjectType; collectErrors(value?: boolean): ObjectType; allowUnknownKeys(value?: boolean): ObjectType; } export type ArrayOptions = { length?: number; min?: number; max?: number; unique?: boolean; predicate?: Predicate[]>['func'] | Predicate[]> | Predicate[]>[]; default?: Infer[] | (() => Infer[]); coerce?: (value: string) => Infer[]; }; export declare class ArrayType extends Type[]> implements WithPredicate[]>, Defaultable[]> { readonly schema: T; private readonly predicates; private readonly defaultValue?; private readonly coerceFn?; private readonly _parse; constructor(schema: T, opts?: ArrayOptions); parse(value?: unknown, parseOptions?: PathOptions & ObjectOptions & { coerced?: boolean; }): Infer[]; length(value: number, errMsg?: ErrMsg[]>): ArrayType; min(value: number, errMsg?: ErrMsg[]>): ArrayType; max(value: number, errMsg?: ErrMsg[]>): ArrayType; unique(): ArrayType; and(schema: K): IntersectionResult; coerce(fn: (value: string) => Infer[]): ArrayType; withPredicate(fn: Predicate[]>['func'], errMsg?: ErrMsg[]>): ArrayType; default(value: Infer[] | (() => Infer[])): ArrayType; } type IntersecWrapper = A extends AnyType ? B extends AnyType ? IntersectionResult : never : never; type JoinLeft = { [idx in keyof A]: idx extends keyof B ? IntersecWrapper : A[idx]; }; type JoinRight = { [idx in keyof B]: idx extends keyof A ? IntersecWrapper : B[idx]; }; type Join = JoinLeft & JoinRight; type InferTuple = { [key in keyof T]: T[key] extends Type ? K : never; }; type TupleOptions = { predicate?: Predicate>['func'] | Predicate> | Predicate>[]; default?: InferTuple | (() => InferTuple); }; export declare class TupleType extends Type> implements WithPredicate>, Defaultable> { private readonly schemas; private readonly predicates; private readonly defaultValue?; constructor(schemas: T, opts?: TupleOptions); parse(value?: unknown): InferTuple; and(schema: K): K extends TupleType ? K extends TupleType ? TupleType> : never : IntersectionType; withPredicate(fn: Predicate>['func'], errMsg?: ErrMsg>): TupleType; default(value: InferTuple | (() => InferTuple)): TupleType; } type InferTupleUnion = Infer; export type UnionOptions = { strict?: boolean; default?: InferTupleUnion | (() => InferTupleUnion); }; type UnionIntersection, T extends AnyType> = U extends UnionType ? UnionType<{ [key in keyof Schemas]: Schemas[key] extends AnyType ? IntersectionResult : Schemas[key]; }> : never; export declare class UnionType extends Type> implements Defaultable> { private readonly schemas; private readonly strict; private readonly defaultValue?; constructor(schemas: T, opts?: UnionOptions); parse(value?: unknown): InferTupleUnion; and(schema: K): UnionIntersection, K>; default(value: InferTupleUnion | (() => InferTupleUnion)): UnionType; } export declare class IntersectionType extends Type & Infer>> { private readonly left; private readonly right; private _schema; constructor(left: T, right: K); parse(value: unknown, opts?: PathOptions & ObjectOptions): Flat & Infer>; and(schema: K): IntersectionType; } type ValueOf = T[keyof T]; type EnumCoerceOptions = 'upper' | 'lower'; export type EnumOptions = { coerce?: EnumCoerceOptions; defaultValue?: ValueOf | (() => ValueOf); }; export declare class EnumType extends Type> implements Defaultable>, WithPredicate> { private readonly enumeration; private values; private readonly defaultValue?; private readonly coerceOpt?; private readonly predicates; constructor(enumeration: T, opts?: EnumOptions); parse(value?: unknown): ValueOf; check(value: unknown): value is ValueOf; and(schema: K): IntersectionType; default(value: ValueOf | (() => ValueOf)): EnumType; coerce(opt: EnumCoerceOptions): EnumType; enum(): T; withPredicate(fn: (value: ValueOf) => boolean, errMsg?: ErrMsg> | undefined): this; } type DeepPartial = { [key in keyof T]?: T[key] extends Object ? Eval> : T[key]; }; export type PartialOpts = { deep: boolean; }; export declare class PartialType extends Type>> : Partial>> { private readonly schema; constructor(schema: T, opts?: K); parse(value: unknown): K extends { deep: true; } ? Eval>> : Partial>; and(schema: K): IntersectionType; } export declare class LazyType AnyType> extends Type>> { private readonly fn; constructor(fn: T); parse(value: unknown, opts?: PathOptions): Infer>; and(schema: K): IntersectionType; }