From 7454bdd3a90059be7fc824aaa25577aee9f5017d Mon Sep 17 00:00:00 2001 From: freisenhauer Date: Sat, 25 Jan 2020 02:02:45 +0100 Subject: [PATCH] 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 --- types/hapi__joi/hapi__joi-tests.ts | 9 +++++++++ types/hapi__joi/index.d.ts | 7 ++++--- 2 files changed, 13 insertions(+), 3 deletions(-) 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; }