Skip to content

Commit

Permalink
Merge pull request #2982 from felixmosh/array-types
Browse files Browse the repository at this point in the history
feat: Improve array().items type
  • Loading branch information
Marsup authored Oct 4, 2023
2 parents 725baf8 + 3463cf0 commit 81277bd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1647,7 +1647,13 @@ declare namespace Joi {
*
* @param type - a joi schema object to validate each array item against.
*/
items(...types: SchemaLikeWithoutArray[]): this;
items<A>(a: SchemaLikeWithoutArray<A>): ArraySchema<A[]>;
items<A, B>(a: SchemaLikeWithoutArray<A>, b: SchemaLikeWithoutArray<B>): ArraySchema<(A | B)[]>;
items<A, B, C>(a: SchemaLikeWithoutArray<A>, b: SchemaLikeWithoutArray<B>, c: SchemaLikeWithoutArray<C>): ArraySchema<(A | B | C)[]>;
items<A, B, C, D>(a: SchemaLikeWithoutArray<A>, b: SchemaLikeWithoutArray<B>, c: SchemaLikeWithoutArray<C>, d: SchemaLikeWithoutArray<D>): ArraySchema<(A | B | C| D)[]>;
items<A, B, C, D, E>(a: SchemaLikeWithoutArray<A>, b: SchemaLikeWithoutArray<B>, c: SchemaLikeWithoutArray<C>, d: SchemaLikeWithoutArray<D>, e: SchemaLikeWithoutArray<E>): ArraySchema<(A | B | C| D | E)[]>;
items<A, B, C, D, E , F>(a: SchemaLikeWithoutArray<A>, b: SchemaLikeWithoutArray<B>, c: SchemaLikeWithoutArray<C>, d: SchemaLikeWithoutArray<D>, e: SchemaLikeWithoutArray<E>, f: SchemaLikeWithoutArray<F>): ArraySchema<(A | B | C| D | E |F)[]>;
items<TItems>(...types: SchemaLikeWithoutArray<TItems>[]): this;

/**
* Specifies the exact number of items in the array.
Expand Down
2 changes: 2 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ expect.error(arrSchema.items([numSchema, strSchema, schemaLike]));
arrSchema = arrSchema.items(schemaMap);
arrSchema = arrSchema.items(schemaMap, schemaMap, schemaLike);
expect.error(arrSchema.items([schemaMap, schemaMap, schemaLike]));
let value1 = Joi.array().items(Joi.string(), Joi.boolean(), Joi.number(), Joi.object({key: Joi.string()}));
expect.type<Joi.ArraySchema<(string | number | boolean | {key: string})[]>>(value1)

// - - - - - - - -

Expand Down

0 comments on commit 81277bd

Please sign in to comment.