How to use yup’s object.shape with typescript?

following the yup guide here you should change your code as follows: import { object, SchemaOf, string } from ‘yup’; interface BaseBootstrapSchema { APPLICATION_NAME: string; LOG_PATH: string; } const bootstrapValidationSchema: SchemaOf<BaseBootstrapSchema> = object({ LOG_PATH: string().required(“The ‘LOG_PATH’ ENV variable is required”), APPLICATION_NAME: string().required(“The ‘APPLICATION_NAME’ ENV variable is required”), }); module.exports = (schema: SchemaOf<BaseBootstrapSchema>) => new Promise((resolve, … Read more

Conditional validation with Yup and Formik

Updated ans: 2023. you can use Yup conditions const validationSchema = Yup.object().shape({ isCompany: Yup.boolean(), companyName: Yup.string().when(‘isCompany’, { is: true, then: Yup.string().required(‘Field is required’) }), companyAddress: Yup.string().when(‘isCompany’, { is: (isCompany) => true,//just an e.g. you can return a function then: Yup.string().required(‘Field is required’), otherwise: Yup.string() }), // test an unconventional type logo: Yup.mixed() .test(‘file_size’, ‘error: file … Read more

Get the value of another field for validation in Yup Schema

number.max cannot reference other field and calculate with it at validation. If you want to do this, you need to implement own schema with mixed.test. Here is a example. tips: number() .min(0, `Minimum tip is $0`) .test({ name: ‘max’, exclusive: false, params: { }, message: ‘${path} must be less than 10% of the price’, test: … Read more

yup validation on multiple values

When using Yup if all normal features fail you, you can use the .test feature, documented here – https://github.com/jquense/yup#mixedtestname-string-message-string–function-test-function-schema mixed.test(name: string, message: string | function, test: function): Schema Adds a test function to the validation chain. Tests are run after any object is cast. Many types have some tests built in, but you can create … Read more

Yup validation with two fields related

An example of a field that requires a numeric value that cannot be higher than the multiplication of two other field’s values const validationSchema = Yup.object().shape({ num1: Yup.number().positive().required(‘This field is required.’), num2: Yup.number().positive().required(‘This field is required.’), num3: Yup.number().positive().required(‘This field is required.’) .when([‘num1’, ‘num2’], (num1, num2, schema) => { return num1 > 0 && num2 > … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)