From e46a5e660c5f4993ce04faebc97fdd0174ed4538 Mon Sep 17 00:00:00 2001 From: Massimo Galbusera Date: Wed, 15 Feb 2023 13:48:32 +0100 Subject: [PATCH] added "dontChangeOptional" boolean to avoid changing optional props in SchemaMap --- lib/index.d.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/index.d.ts b/lib/index.d.ts index 8d0f415b..60ceb6e8 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -793,12 +793,22 @@ declare namespace Joi { type PartialSchemaMap = { [key in keyof TSchema]?: SchemaLike | SchemaLike[]; } + + type PartialUnchangedSchemaMap = { + [key in keyof TSchema]: SchemaLike | SchemaLike[]; + } type StrictSchemaMap = { [key in keyof TSchema]-?: ObjectPropertiesSchema }; - type SchemaMap = isStrict extends true ? StrictSchemaMap : PartialSchemaMap + type StrictUnchangedSchemaMap = { + [key in keyof TSchema]: ObjectPropertiesSchema + }; + + type SchemaMap = isStrict extends true + ? (dontChangeOptional extends true ? StrictUnchangedSchemaMap : StrictSchemaMap) + : (dontChangeOptional extends true ? PartialUnchangedSchemaMap : PartialSchemaMap); type Schema

= | AnySchema

@@ -2100,7 +2110,7 @@ declare namespace Joi { * Generates a schema object that matches an object data type (as well as JSON strings that have been parsed into objects). */ // tslint:disable-next-line:no-unnecessary-generics - object(schema?: SchemaMap): ObjectSchema; + object(schema?: SchemaMap): ObjectSchema; /** * Generates a schema object that matches a string data type. Note that empty strings are not allowed by default and must be enabled with allow('').