/** * @Author: Rostislav Simonik * @Author: Erik Slovak * @Date: 2020-10-04T15:10:83+02:00 * @Copyright: Technology Studio **/ import type { Schema, AnyObject, Maybe, Message, Flags, MakePartial, setLocale, } from 'yup' // NOTE: imported from yup/util/types.ts /* this seems to force TS to show the full type instead of all the wrapped generics */ // eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/naming-convention type _ = T extends {} ? { [k in keyof T]: T[k] } : T // NOTE: imported from yup/object.ts type MakeKeysOptional = T extends AnyObject ? _> : T declare module 'yup' { interface ObjectSchema< TIn extends Maybe, TContext = AnyObject, // eslint-disable-next-line @typescript-eslint/no-explicit-any TDefault = any, TFlags extends Flags = '', > extends Schema, TContext, TDefault, TFlags> { requiredRelation: (idKey?: string) => this, atLeastOneRequired: (keys: string[]) => this, } interface StringSchema< TType extends Maybe = string | undefined, TContext = AnyObject, TDefault = undefined, TFlags extends Flags = '', > extends Schema { decimal: () => StringSchema, numbersOnly: () => StringSchema, numeric: () => StringSchema, phoneNumber: () => StringSchema, equalsTo: () => StringSchema, } interface StringLocale { decimal?: Message, numbersOnly?: Message, numeric?: Message, phoneNumber?: Message, equalsTo?: Message, } interface DateLocale { required?: Message, } interface ObjectLocale { atLeastOneRequired?: Message, } } export type YupLocaleObject = Parameters[0] export type StringLocale = YupLocaleObject['string'] & { decimal?: Message, numbersOnly?: Message, numeric?: Message, phoneNumber?: Message, equalsTo?: Message, } export type DateLocale = YupLocaleObject['date'] & { required?: Message, } export type ObjectLocale = YupLocaleObject['object'] & { atLeastOneRequired?: Message, } export type LocaleObject = YupLocaleObject & { date?: DateLocale, string?: StringLocale, object?: ObjectLocale, }