diff --git a/types/hapi__joi/hapi__joi-tests.ts b/types/hapi__joi/hapi__joi-tests.ts index aabf2d22df..6aae5d9f41 100644 --- a/types/hapi__joi/hapi__joi-tests.ts +++ b/types/hapi__joi/hapi__joi-tests.ts @@ -1012,11 +1012,18 @@ const Joi3 = Joi.extend({ asd: { args: [ { - name: 'allowFalse' + name: 'allowFalse', + ref: true, + assert: Joi.boolean(), } ], - method(allowFalse) { - this.$_createError(str, {}, {}, {}, {}); + method(allowFalse: boolean) { + return this.$_addRule({ + name: 'asd', + args: { + allowFalse, + } + }); }, validate(value: boolean, helpers, params, options) { if (value || params.allowFalse && !value) { diff --git a/types/hapi__joi/index.d.ts b/types/hapi__joi/index.d.ts index 8747cc35f5..cfed3f7f56 100644 --- a/types/hapi__joi/index.d.ts +++ b/types/hapi__joi/index.d.ts @@ -679,6 +679,13 @@ declare namespace Joi { type SchemaFunction = (schema: Schema) => Schema; + interface AddRuleOptions { + name: string; + args?: { + [key: string]: any; + }; + } + interface SchemaInternals { /** * Parent schema object. @@ -693,7 +700,7 @@ declare namespace Joi { /** * Adds a rule to current validation schema. */ - $_addRule(rule: string | ExtensionRule): Schema; + $_addRule(rule: string | AddRuleOptions): Schema; /** * Internally compiles schema. @@ -1756,7 +1763,7 @@ declare namespace Joi { interface RuleArgs { name: string; ref?: boolean; - assert?: (value: any) => boolean; + assert?: ((value: any) => boolean) | AnySchema; message?: string; /**