From de683448f95101da49e6c4a4887c280e0eeb2428 Mon Sep 17 00:00:00 2001 From: Felix Mosheev <9304194+felixmosh@users.noreply.github.com> Date: Thu, 24 Aug 2023 12:38:47 +0300 Subject: [PATCH] feat: Improve object type --- lib/index.d.ts | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/lib/index.d.ts b/lib/index.d.ts index aba7fa59..f666700e 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -814,15 +814,13 @@ declare namespace Joi { ? (StrictSchemaMap | ObjectSchema) : never - type PartialSchemaMap = { - [key in keyof TSchema]?: SchemaLike | SchemaLike[]; - } - type StrictSchemaMap = { [key in keyof TSchema]-?: ObjectPropertiesSchema }; - type SchemaMap = isStrict extends true ? StrictSchemaMap : PartialSchemaMap + type SchemaMap = { + [key in keyof TSchema]: Schema | TSchema[key] + } type Schema

= | AnySchema

@@ -1711,8 +1709,8 @@ declare namespace Joi { /** * Appends the allowed object keys. If schema is null, undefined, or {}, no changes will be applied. */ - append(schema?: SchemaMap): this; - append(schema?: SchemaMap): ObjectSchema + append(schema?: TSchemaExtended): this; + append(schema?: SchemaMap): ObjectSchema /** * Verifies an assertion where. @@ -1731,7 +1729,8 @@ declare namespace Joi { /** * Sets or extends the allowed object keys. */ - keys(schema?: SchemaMap): this; + keys(schema?: TSchemaExtended): this; + keys(schema?: SchemaMap): ObjectSchema; /** * Specifies the exact number of keys in the object. @@ -1790,7 +1789,7 @@ declare namespace Joi { /** * Renames a key to another name (deletes the renamed key). */ - rename(from: string | RegExp, to: string, options?: RenameOptions): this; + rename(from: From | RegExp, to: To, options?: RenameOptions): ObjectSchema> & {[P in To]: TSchema[From]}>; /** * Requires the object to be a Joi schema instance. @@ -1805,12 +1804,12 @@ declare namespace Joi { /** * Requires the presence of other keys whenever the specified key is present. */ - with(key: string, peers: string | string[], options?: DependencyOptions): this; + with(key: Key, peers: Exclude | Exclude[], options?: DependencyOptions): this; /** * Forbids the presence of other keys whenever the specified is present. */ - without(key: string, peers: string | string[], options?: DependencyOptions): this; + without(key: Key, peers: Exclude | Exclude[], options?: DependencyOptions): this; /** * Defines an exclusive relationship between a set of keys. one of them is required but not at the same time. @@ -2123,8 +2122,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('').