How to use the yup.ValidationError.isError function in yup

To help you get started, we’ve selected a few yup examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / yup / yup-tests.ts View on Github external
});
const renderable = yup.lazy(value => {
    switch (typeof value) {
        case 'number':
            return yup.number();
        case 'string':
            return yup.string();
        default:
            return yup.mixed();
    }
});
const renderables = yup.array().of(renderable);

// ValidationError static methods
// $ExpectType boolean
ValidationError.isError(new ValidationError('error', 'value', 'path'));
// $ExpectType string | ((params?: any) => string)
ValidationError.formatError('error', { path: 'path' });
ValidationError.formatError('error');
ValidationError.formatError(() => 'error');
ValidationError.formatError(() => 'error', { path: 'path' });

// ValidationError
let error: ValidationError = new yup.ValidationError('error', 'value', 'path');
error = new yup.ValidationError(['error', 'error2'], true, 'path');
error = new yup.ValidationError(['error', 'error2'], 5, 'path');
error = new yup.ValidationError(['error', 'error2'], { name: 'value' }, 'path');
error = new yup.ValidationError(['error', 'error2'], { name: 'value' }, 'path', 'type');
error = {
    name: 'ValidationError',
    message: 'error',
    path: 'path',
github kalmhq / kalm / frontend / src / forms / validator.ts View on Github external
return function (values: T[]) {
    try {
      arraySchema.validateSync(values);
    } catch (e) {
      if (!ValidationError.isError(e)) {
        throw e;
      }

      return e.errors[0] || "Unknown error";
    }

    if (v.length === 0) {
      return undefined;
    }

    const validateFunction = yupValidatorWrap(...v);

    const errors = values.map((value) => validateFunction(value));

    if (errors.findIndex((x) => !!x) < 0) {
      return undefined;