-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Validate in schema options is not properly typed #14696
Labels
Milestone
Comments
vkarpov15
added a commit
that referenced
this issue
Jul 4, 2024
types: correct `this` for `validate.validator` schematype option
This was referenced Jul 27, 2024
This was referenced Sep 3, 2024
Re opening based on comments in #14720 |
import { Schema } from "mongoose";
interface User {
name: string;
isActive: boolean;
}
const userSchema = new Schema<User>({
name: {
type: String,
required: [true, "Name on card is required"],
},
isActive: {
type: Boolean,
default: false,
validate: {
validator(this: User, v: boolean) {
// Now `this` is properly typed as `User`
return !v || this.name === "super admin";
},
},
},
}); TRY THESE ONE! |
vkarpov15
added a commit
that referenced
this issue
Nov 8, 2024
BREAKING CHANGE: change `this` to HydratedDocument for default() and required(), HydratedDocument | Query for validate()
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Prerequisites
Mongoose version
8.3.1
Node.js version
18.17.1
MongoDB server version
6
Typescript version (if applicable)
4.8
Description
The validate config is not properly typed in schema options e.g
Steps to Reproduce
Expected Behavior
I would expect that
this
is properly typed.The text was updated successfully, but these errors were encountered: