From 31015de2f7958bd8428c8cec25c28d1149912c35 Mon Sep 17 00:00:00 2001 From: Ernie Casilla Date: Sun, 14 Apr 2019 09:58:33 -0400 Subject: [PATCH] fix: Added Unique Array options. --- types/joi/index.d.ts | 6 +++++- types/joi/joi-tests.ts | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/types/joi/index.d.ts b/types/joi/index.d.ts index c943fbfa33..35e386a928 100644 --- a/types/joi/index.d.ts +++ b/types/joi/index.d.ts @@ -209,6 +209,10 @@ export interface StringRegexOptions { invert?: boolean; } +export interface ArrayUniqueOptions { + ignoreUndefined?: boolean; +} + export interface JoiObject { isJoi: boolean; } @@ -762,7 +766,7 @@ export interface ArraySchema extends AnySchema { * Be aware that a deep equality is performed on elements of the array having a type of object, * a performance penalty is to be expected for this kind of operation. */ - unique(comparator?: string): this; + unique(comparator?: string, options?: ArrayUniqueOptions): this; unique(comparator?: (a: T, b: T) => boolean): this; } diff --git a/types/joi/joi-tests.ts b/types/joi/joi-tests.ts index b4f01cfe56..af232a269d 100644 --- a/types/joi/joi-tests.ts +++ b/types/joi/joi-tests.ts @@ -328,6 +328,7 @@ arrSchema = arrSchema.length(ref); arrSchema = arrSchema.unique(); arrSchema = arrSchema.unique((a, b) => a.test === b.test); arrSchema = arrSchema.unique('customer.id'); +arrSchema = arrSchema.unique('customer.id', {ignoreUndefined: true}); arrSchema = arrSchema.items(numSchema); arrSchema = arrSchema.items(numSchema, strSchema, schemaLike);