From 2fa0eebeb70d2fb6dc4f09409dd75459449ed8a1 Mon Sep 17 00:00:00 2001 From: Miro Yovchev Date: Wed, 4 Sep 2019 00:44:48 +0300 Subject: [PATCH] [@types/hapi__joi] Add number type to ValidationErrorItem path property (#38036) * Add number type to ValidationErrorItem.path * Formatting --- types/hapi__joi/hapi__joi-tests.ts | 11 ++++++++++- types/hapi__joi/index.d.ts | 11 ++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/types/hapi__joi/hapi__joi-tests.ts b/types/hapi__joi/hapi__joi-tests.ts index e0e65a5de4..e7f0645497 100644 --- a/types/hapi__joi/hapi__joi-tests.ts +++ b/types/hapi__joi/hapi__joi-tests.ts @@ -6,6 +6,7 @@ let x: any = null; declare const value: any; let num = 0; let str = ''; +let strOrNum: string | number; declare const bool: boolean; declare const exp: RegExp; declare const obj: object; @@ -184,6 +185,14 @@ validErrItem = { context: obj }; +validErrItem = { + message: str, + type: str, + path: [str, num, str], + options: validOpts, + context: obj, +}; + validErrFunc = errs => errs; validErrFunc = errs => errs[0]; validErrFunc = errs => 'Some error'; @@ -940,7 +949,7 @@ schema = Joi.lazy(() => schema, { once: true }); Joi.validate(value, schema, validOpts, (err, value) => { x = value; str = err.message; - str = err.details[0].path[0]; + strOrNum = err.details[0].path[0]; str = err.details[0].message; str = err.details[0].type; }); diff --git a/types/hapi__joi/index.d.ts b/types/hapi__joi/index.d.ts index 2ddc87d837..d46494703c 100644 --- a/types/hapi__joi/index.d.ts +++ b/types/hapi__joi/index.d.ts @@ -18,6 +18,7 @@ // Alejandro Fernandez Haro // Silas Rech // Anand Chowdhary +// Miro Yovchev // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.4 @@ -281,11 +282,11 @@ export interface ValidationError extends Error, JoiObject { } export interface ValidationErrorItem { - message: string; - type: string; - path: string[]; - options?: ValidationOptions; - context?: Context; + message: string; + type: string; + path: Array; + options?: ValidationOptions; + context?: Context; } export type ValidationErrorFunction = (errors: ValidationErrorItem[]) => string | ValidationErrorItem | ValidationErrorItem[] | Error;