export interface CustomRestrictCallback { (value: T): any; } export interface DefaultCallback { (value: T): any; } export interface ErrorCallback { (message: string): string; } export interface FormatCallback { (value: T): any; } export interface SilentResult { error?: Error; value?: any; } export interface SchemaBase { required(strict?: boolean): this; custom(restrictFn: CustomRestrictCallback, ctx?: any): this; default(value: DefaultCallback | any, strict?: boolean, ctx?: any): this; error(message: string | ErrorCallback, ctx?: any): this; errorForAll(message: string | ErrorCallback, ctx?: any): this; format(callback: FormatCallback, ctx?: any): this; validate(value: any): any; validateSilent(value: any): SilentResult; } export type ArrayConfig = SchemaBase; export interface ObjectConfig { [x: string]: any; } export interface SchemaAny extends SchemaBase { enum(...values: any[]): this; } export interface SchemaArray extends SchemaBase { min(min: number, strict?: boolean): this; max(max: number, strict?: boolean): this; } export interface SchemaBoolean extends SchemaBase { default(value: DefaultCallback | any, ctx?: any): this; required(): this; enum(...values: boolean[]): this; } export interface SchemaNumber extends SchemaBase { default(value: DefaultCallback | any, ctx?: any): this; required(): this; enum(...values: number[]): this; min(min: number, strict?: boolean): this; max(max: number, strict?: boolean): this; int(): this; even(): this; odd(): this; allowNaN(): this; allowInfinity(): this; allowString(): this; } export interface SchemaObject extends SchemaBase { allowUnknown(): this; stripUnknown(): this; } export interface SchemaString extends SchemaBase { enum(...values: string[]): this; min(min: number, strict?: boolean): this; max(max: number, strict?: boolean): this; pattern(pattern: RegExp): this; } export interface SchemaMixed extends SchemaBase {} export function any(): SchemaAny; export function array(config?: ArrayConfig): SchemaArray; export function boolean(): SchemaBoolean; export function number(): SchemaNumber; export function object(config?: ObjectConfig): SchemaObject; export function string(): SchemaString; export function mixed(): SchemaMixed; export type Schema = SchemaAny | SchemaArray | SchemaBoolean | SchemaNumber | SchemaObject | SchemaString | SchemaMixed;