hapi__joi make error attributes on validation result optional (#41609)

* make error attributes on validation result optional according documentation of hapi__joi

* add frederic reisenhauer to hapi__joi contributors

* change double quotes to single quotes
This commit is contained in:
freisenhauer 2020-01-25 02:02:45 +01:00 committed by Ben Lichtman
parent 0a32b87d14
commit 7454bdd3a9
2 changed files with 13 additions and 3 deletions

View File

@ -944,6 +944,9 @@ schema = Joi.link(str);
value = schema.validate(value).value;
result = schema.validate(value);
if (result.error) {
throw Error('error should not be set');
}
result = schema.validate(value, validOpts);
asyncResult = schema.validateAsync(value);
asyncResult = schema.validateAsync(value, validOpts);
@ -952,6 +955,12 @@ schema = Joi.link(str);
.then(val => JSON.stringify(val, null, 2))
.then(val => { throw new Error('one error'); })
.catch(e => { });
const falsyValue = { username: 'example' };
result = schema.validate(falsyValue);
if (!result.error) {
throw Error('error should be set');
}
}
}

View File

@ -20,6 +20,7 @@
// Anand Chowdhary <https://github.com/AnandChowdhary>
// Miro Yovchev <https://github.com/myovchev>
// David Recuenco <https://github.com/RecuencoJones>
// Frederic Reisenhauer <https://github.com/freisenhauer>
// Stefan-Gabriel Muscalu <https://github.com/legraphista>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
@ -616,9 +617,9 @@ declare namespace Joi {
type ValidationErrorFunction = (errors: ValidationErrorItem[]) => string | ValidationErrorItem | Error;
interface ValidationResult<T = any> {
error: ValidationError;
errors: ValidationError;
warning: ValidationError;
error?: ValidationError;
errors?: ValidationError;
warning?: ValidationError;
value: T;
}