Skip to content

types(schema): use user-provided THydratedDocumentType as context for virtual get() and set() #15517

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

Merged
merged 2 commits into from
Jul 7, 2025

Conversation

vkarpov15
Copy link
Collaborator

Fix #15516

Summary

Quick fix: should use user-specified THydratedDocumentType

Examples

@vkarpov15 vkarpov15 added this to the 8.16.2 milestone Jul 5, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR ensures that user-specified THydratedDocumentType is correctly applied as the this context for virtual getters and setters in Schema.

  • Added a new test function gh15516 in schema.test.ts
  • Expanded Schema generics to include a custom HydratedUserDoc type
  • Asserts that this inside the virtual getter is correctly typed
Comments suppressed due to low confidence (1)

test/types/schema.test.ts:1854

  • The test only covers the virtual getter; consider adding a corresponding assertion for the virtual setter to ensure the this context is also correctly typed when setting the virtual property.
  schema.virtual('myVirtual').get(function () {

Copy link
Collaborator

@hasezoey hasezoey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, aside from lint and types test not running due to it.

@hasezoey hasezoey added the typescript Types or Types-test related issue / Pull Request label Jul 6, 2025
@vkarpov15 vkarpov15 merged commit b83217c into master Jul 7, 2025
5 checks passed
@hasezoey hasezoey deleted the vkarpov15/gh-15516 branch July 8, 2025 06:32
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.

[Types] Schema.virtual() doesn't use THydratedDocumentType
2 participants