Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(index.d.ts): allow required function in array definition #9888

Merged
merged 1 commit into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 10 additions & 1 deletion test/typescript/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]
}
});

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

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