Skip to content

Commit

Permalink
fix(index.d.ts): allow required function in array definition
Browse files Browse the repository at this point in the history
  • Loading branch information
Ugzuzg committed Feb 2, 2021
1 parent 5c7d047 commit 3b05313
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion test/typescript/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']
}
});

Expand Down Expand Up @@ -68,4 +72,4 @@ async function gh9857() {
};

const schema = new Schema<UserDocument, UserModel, User>(schemaDefinition);
}
}

0 comments on commit 3b05313

Please sign in to comment.