[@types/hapi__joi] Add number type to ValidationErrorItem path property (#38036)

* Add number type to ValidationErrorItem.path

* Formatting
This commit is contained in:
Miro Yovchev 2019-09-04 00:44:48 +03:00 committed by Ron Buckton
parent d2e519565f
commit 2fa0eebeb7
2 changed files with 16 additions and 6 deletions

View File

@ -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;
});

View File

@ -18,6 +18,7 @@
// Alejandro Fernandez Haro <https://github.com/afharo>
// Silas Rech <https://github.com/lenovouser>
// Anand Chowdhary <https://github.com/AnandChowdhary>
// Miro Yovchev <https://github.com/myovchev>
// 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<string | number>;
options?: ValidationOptions;
context?: Context;
}
export type ValidationErrorFunction = (errors: ValidationErrorItem[]) => string | ValidationErrorItem | ValidationErrorItem[] | Error;