From 35d241168a5f2122a9ecf56202cf089454ff1e20 Mon Sep 17 00:00:00 2001 From: Alexandre Germain Date: Mon, 17 Feb 2025 13:37:13 +0100 Subject: [PATCH] chore: improve expression types --- lib/index.d.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/index.d.ts b/lib/index.d.ts index c224c991..d6ee5f50 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -26,7 +26,7 @@ declare namespace Joi { type BasicType = boolean | number | string | any[] | object | null; - type LanguageMessages = Record>; + type LanguageMessages = Record>; type PresenceMode = 'optional' | 'required' | 'forbidden'; @@ -641,6 +641,10 @@ declare namespace Joi { render?: boolean; } + interface ExpressionOptions extends ReferenceOptions { + functions: Record unknown> + } + interface StringRegexOptions { /** * optional pattern name. @@ -1987,6 +1991,11 @@ declare namespace Joi { toString(): string; } + interface Template { + render(value: any, state: State, prefs: any, local: any, options?: any): string + toString(): string; + } + type ExtensionBoundSchema = Schema & SchemaInternals; interface RuleArgs { @@ -2260,7 +2269,7 @@ declare namespace Joi { /** * Generates a dynamic expression using a template string. */ - expression(template: string, options?: ReferenceOptions): any; + expression(template: string, options?: ExpressionOptions): Template; /** * Creates a new Joi instance customized with the extension(s) you provide included. @@ -2324,8 +2333,9 @@ declare namespace Joi { /** * Generates a dynamic expression using a template string. + * @see {@link Root.expression} */ - x(template: string, options?: ReferenceOptions): any; + x(template: string, options?: ExpressionOptions): Template; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- // Below are undocumented APIs. use at your own risk