From e1e6c0c5b6309f69900e9ea9a898a914d61415bf 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 | 11 ++++++++++- 2 files changed, 11 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..4aed0505b31 100644 --- a/test/typescript/schema.ts +++ b/test/typescript/schema.ts @@ -23,6 +23,15 @@ const movieSchema: Schema = new Schema({ type: String, enum: Genre, required: true + }, + actionIntensity: { + type: Number, + required: [ + function(this: { genre: Genre }) { + return this.genre === Genre.Action; + }, + 'Action intensity required for action genre' + ] } }); @@ -68,4 +77,4 @@ async function gh9857() { }; const schema = new Schema(schemaDefinition); -} \ No newline at end of file +}