diff --git a/types/hapi__joi/hapi__joi-tests.ts b/types/hapi__joi/hapi__joi-tests.ts index c7535d3c9f..bec6360f5c 100644 --- a/types/hapi__joi/hapi__joi-tests.ts +++ b/types/hapi__joi/hapi__joi-tests.ts @@ -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'); + } } } diff --git a/types/hapi__joi/index.d.ts b/types/hapi__joi/index.d.ts index 6444ce5b6b..30b0818c22 100644 --- a/types/hapi__joi/index.d.ts +++ b/types/hapi__joi/index.d.ts @@ -20,6 +20,7 @@ // Anand Chowdhary // Miro Yovchev // David Recuenco +// Frederic Reisenhauer // Stefan-Gabriel Muscalu // 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 { - error: ValidationError; - errors: ValidationError; - warning: ValidationError; + error?: ValidationError; + errors?: ValidationError; + warning?: ValidationError; value: T; }