From 3b0531310916107c9ba585541a626cffff793339 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaras=C5=82a=C5=AD=20Viktor=C4=8Dyk?= Date: Tue, 2 Feb 2021 11:01:22 -0100 Subject: [PATCH] fix(index.d.ts): allow required function in array definition --- index.d.ts | 2 +- test/typescript/schema.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index 8706df16808..83da784a8ab 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1381,7 +1381,7 @@ declare module 'mongoose' { * path cannot be set to a nullish value. If a function, Mongoose calls the * function and only checks for nullish values if the function returns a truthy value. */ - required?: boolean | (() => boolean) | [boolean, string]; + required?: boolean | (() => boolean) | [boolean, string] | [() => boolean, string]; /** * The default value for this path. If a function, Mongoose executes the function diff --git a/test/typescript/schema.ts b/test/typescript/schema.ts index c6f61667b95..bc402a94908 100644 --- a/test/typescript/schema.ts +++ b/test/typescript/schema.ts @@ -23,6 +23,10 @@ const movieSchema: Schema = new Schema({ type: String, enum: Genre, required: true + }, + actionIntensity: { + type: Number, + required: [function () { return this.genre === Genre.Action; }, 'Action intensity required for action genre'] } }); @@ -68,4 +72,4 @@ async function gh9857() { }; const schema = new Schema(schemaDefinition); -} \ No newline at end of file +}