-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
types: correct this
for validate.validator
schematype option
#14720
Conversation
For context: I'm upgrading from Mongoose v8.2.2 to v8.6.3 When performing a document create/update, However, I believe due to these type changes make in this PR, Typescript seems to believe that Do you have any idea on how I can type the validator function so that Typescript knows that EDIT: After some experimentation, I managed to get the following somewhat working solution by specifying the type of
|
@pharapeti you're right that the workaround is to explicitly set the type of |
@vkarpov15 Thanks for confirming that, will implement the workaround for now 👍 Cheers for the speedy reply 🙏 |
pharapeti's workaround no longer appears to work as of v8.9.7. Using the same example provided, I get the following error on the type of 'this': It seems that the validator function is now expecting the 'this' argument to be of the 'PassPersisted' type, which I assume is the raw unhydrated data type representing what is stored in MongoDB. This does not align with my understanding of what is written in the docs at all. |
@RadotJar can you please open a new issue and follow the issue template? |
I have created one here: #15242 |
Fix #14696
Summary
Ensure
this
has the correct type invalidate.validator
below.I made 2 changes to support this:
EnforcedDocType
down toValidateFn
viaValidateOpts
andSchemaValidator
LegacyAsyncValidateFn
. For some reason,LegacyAsyncValidateFn
breaks these tests, and I have no idea why. It has something to do with thedone
function. Either way,LegacyAsyncValidateFn
is no longer necessary because we removed support for validators that receive a callback in Mongoose 6, so I think it is safe to remove.Examples