import { ArraySchema } from './array'; import { BooleanSchema } from './boolean'; import { DateSchema } from './date'; import { LocaleValue, MixedLocale } from './Locale'; import { NumberSchema } from './number'; import { ObjectSchema } from './object'; import { Refable } from './ref'; import { StringSchema } from './string'; import { ValidationError } from './ValidationError'; export interface SchemaDescription { type: string; label: string; meta: {}; tests: Array<{ name: string; params: {}; }>; } export interface SchemaValidateOptions { strict?: boolean; abortEarly?: boolean; stripUnknown?: boolean; recursive?: boolean; context?: {}; } export interface SchemaTestOptions { name: string; message: LocaleValue; test: (this: { path: string; schema: TSchema; options: SchemaValidateOptions; parent: any; createError: (options: { path: string; message: LocaleValue; params?: TParams; }) => ValidationError; }, value: TValue) => boolean | Promise; params?: TParams; exclusive?: boolean; } export interface MixedSchema { __isYupSchema__: true; type: 'mixed' | 'string' | 'number' | 'boolean' | 'object' | 'date' | 'array'; clone(): this; label(label: string): this; meta(meta: {}): this; describe(): SchemaDescription; /** @类型不友好 */ concat(schema: MixedSchema): this; validate(value: T, options?: SchemaValidateOptions): Promise; validateSync(value: T, options?: SchemaValidateOptions): T; /** * 验证增强,包括:对象顺序验证、返回结果包含错误信息。 */ validatePlus(value: T, options?: SchemaValidateOptions): Promise<{ error?: ValidationError; data: T; }>; /** * 验证增强,包括:对象顺序验证、返回结果包含错误信息。 */ validatePlusSync(value: T, options?: SchemaValidateOptions): { error?: ValidationError; data: T; }; /** @类型不友好 */ validateAt(path: string, value: any, options?: SchemaValidateOptions): Promise; /** @类型不友好 */ validateSyncAt(path: string, value: any, options?: SchemaValidateOptions): any; isValid(value: T, options?: SchemaValidateOptions): Promise; isValidSync(value: T, options?: SchemaValidateOptions): boolean; cast(value: T, options?: SchemaValidateOptions): any; isType(value: T): boolean; strict(isStrict?: boolean): this; strip(stripField?: boolean): this; withMutation(fn: (schema: this) => X): X; default(value: T | (() => T)): this; default(): T | undefined; nullable(isNullable?: boolean): this; allowEmptyString(): this; required(message?: MixedLocale['required']): this; notRequired(): this; defined(): this; typeError(message: LocaleValue): this; oneOf(arrayOfValues: Record | Refable[], message?: MixedLocale['oneOf']): this; /** oneOf 的别名 */ enum(arrayOfValues: Record | Refable[], message?: MixedLocale['oneOf']): this; /** oneOf 的别名 */ equals(arrayOfValues: Record | Refable[], message?: MixedLocale['oneOf']): this; notOneOf(arrayOfValues: Refable[], message?: MixedLocale['notOneOf']): this; when(builder: (value: T, schema: this) => this): this; when(key: string, builder: { is: boolean | ((value: V) => boolean); then: GetSchema; otherwise: GetSchema; }): this; when(key: string, builder: (value: V, schema: this) => this): this; test(test: SchemaTestOptions['test'] | RegExp, message?: SchemaTestOptions['message']): this; test(options: SchemaTestOptions): this; transform(transformer: (this: this, currentValue: T, originalValue: T) => T): this; } export type GetSchema = ([ T ] extends [string] ? StringSchema : [T] extends [number] ? NumberSchema : [T] extends [boolean] ? BooleanSchema : [T] extends [Date] ? DateSchema : T extends Array ? ArraySchema : T extends {} ? ObjectSchema : MixedSchema) | MixedSchema; export type GetObjectSchema = { [K in keyof T]: GetSchema; }; export declare function mixed(payload?: (schema: MixedSchema) => MixedSchema): MixedSchema;