Skip to content

Commit 1430138

Browse files
committed
fix: prevent boolean distribution on ArraySchema
1 parent 05599ac commit 1430138

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/index.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ declare namespace Joi {
439439
domain?: DomainOptions;
440440
/**
441441
* Encode URI before validation.
442-
*
442+
*
443443
* @default false
444444
*/
445445
encodeUri?: boolean;
@@ -785,7 +785,8 @@ declare namespace Joi {
785785

786786
type Primitives = string | number | boolean | bigint | symbol | null;
787787

788-
type SchemaLikeWithoutArray<TSchema = any> = TSchema extends any[] ? never :
788+
type IsArray<T> = T extends any[] ? true : false;
789+
type SchemaLikeWithoutArray<TSchema = any> = IsArray<TSchema> extends true ? never :
789790
(Primitives | Schema<TSchema> | SchemaMap<TSchema>);
790791
type SchemaLike<TSchema = any> = SchemaLikeWithoutArray<TSchema> | object;
791792

test/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,8 @@ expect.error(arrSchema.items([schemaMap, schemaMap, schemaLike]));
401401
let value1 = Joi.array().items(Joi.string(), Joi.boolean(), Joi.number(), Joi.object({key: Joi.string()}));
402402
expect.type<Joi.ArraySchema<(string | number | boolean | {key: string})[]>>(value1)
403403

404+
expect.type<Joi.ArraySchema<boolean[]>>(Joi.array().items(Joi.boolean()));
405+
404406
// - - - - - - - -
405407

406408
{

0 commit comments

Comments
 (0)