mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
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:
parent
0a32b87d14
commit
7454bdd3a9
@ -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');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
7
types/hapi__joi/index.d.ts
vendored
7
types/hapi__joi/index.d.ts
vendored
@ -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;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user