diff --git a/types/joi/index.d.ts b/types/joi/index.d.ts index c0007d1fbc..5c271dc073 100644 --- a/types/joi/index.d.ts +++ b/types/joi/index.d.ts @@ -6,6 +6,19 @@ // TODO express type of Schema in a type-parameter (.default, .valid, .example etc) +export type Types = 'any' | 'alternatives' | 'array' | 'string' | 'number' | 'object' | 'boolean' | 'binary' | 'date' | 'function' | 'lazy'; + +export type LanguageRuleOptions = string | false | { + [key: string]: LanguageRuleOptions; +}; + +export type LanguageOptions = { + root?: string; + key?: string; + messages?: { wrapArrays?: boolean; }; +} & Partial> & { + [key: string]: LanguageRuleOptions; +}; export interface ValidationOptions { /** @@ -35,7 +48,7 @@ export interface ValidationOptions { /** * overrides individual error messages. Defaults to no override ({}). */ - language?: Object; + language?: LanguageOptions; /** * sets the default presence requirements. Supported modes: 'optional', 'required', and 'forbidden'. Defaults to 'optional'. */ @@ -844,9 +857,7 @@ export interface Extension { name: string; base?: Schema; pre?: (this: AnySchema>, params: { [key: string]: any }, value: any, state: State, options: ValidationOptions) => Err | void; - language?: { - [key: string]: string; - }, + language?: LanguageRuleOptions; describe?: (this: AnySchema>, description: any) => any; rules?: Rules[]; } diff --git a/types/joi/joi-tests.ts b/types/joi/joi-tests.ts index 63b247bc98..4a073fb27a 100644 --- a/types/joi/joi-tests.ts +++ b/types/joi/joi-tests.ts @@ -53,10 +53,25 @@ validOpts = { stripUnknown: bool }; validOpts = { stripUnknown: { arrays: bool } }; validOpts = { stripUnknown: { objects: bool } }; validOpts = { stripUnknown: { arrays: bool, objects: bool } }; -validOpts = { language: bool }; validOpts = { presence: str }; validOpts = { context: obj }; validOpts = { noDefaults: bool }; +validOpts = { + language: { + root: str, + key: str, + messages: { wrapArrays: bool }, + string: { base: str }, + number: { base: str }, + object: { + base: false, + children: { childRule: str } + }, + customType: { + customRule: str + } + } +}; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---