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

types: correct this for validate.validator schematype option #14720

Merged
merged 2 commits into from
Jul 4, 2024

Conversation

vkarpov15
Copy link
Collaborator

Fix #14696

Summary

Ensure this has the correct type in validate.validator below.

    isActive: {
      type: Boolean,
      default: false,
      validate: {
        validator(v: any) {
          expectAssignable<User>(this);
          return !v || this.name === 'super admin';
        }
      }
    }

I made 2 changes to support this:

  1. passing EnforcedDocType down to ValidateFn via ValidateOpts and SchemaValidator
  2. Removing LegacyAsyncValidateFn. For some reason, LegacyAsyncValidateFn breaks these tests, and I have no idea why. It has something to do with the done 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

@vkarpov15 vkarpov15 added this to the 8.4.5 milestone Jul 2, 2024
@vkarpov15 vkarpov15 modified the milestones: 8.4.5, 8.4.6 Jul 3, 2024
@hasezoey hasezoey added the typescript Types or Types-test related issue / Pull Request label Jul 4, 2024
@vkarpov15 vkarpov15 merged commit 54561d0 into master Jul 4, 2024
5 checks passed
@vkarpov15 vkarpov15 deleted the vkarpov15/gh-14696 branch July 4, 2024 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typescript Types or Types-test related issue / Pull Request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Validate in schema options is not properly typed
2 participants