Skip to content

types(model): use ProjectionType for Model.hydrate() #15443

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 1 commit into from
May 30, 2025

Conversation

vkarpov15
Copy link
Collaborator

Fix #15437

Summary

Examples

@vkarpov15 vkarpov15 added this to the 8.15.2 milestone May 28, 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 updates the type definitions for Model.hydrate() to use ProjectionType, ensuring that only the projected fields are typed accordingly.

  • Adds a new test case (gh15437) in test/types/models.test.ts demonstrating the behavior of hydrating a document with a string projection.
  • Verifies that projected fields are correctly typed while non-projected fields remain assignable to undefined, null, or their original type.
Comments suppressed due to low confidence (1)

test/types/models.test.ts:1034

  • Consider adding a runtime check (e.g., an explicit equality assertion) to verify that 'doc1.address' is undefined when it is not projected, which can further validate the projection behavior at runtime.
expectAssignable<undefined | null | string>(doc1.address);

@hasezoey hasezoey added the typescript Types or Types-test related issue / Pull Request label May 29, 2025
@vkarpov15 vkarpov15 merged commit ef87599 into master May 30, 2025
6 checks passed
@hasezoey hasezoey deleted the vkarpov15/gh-15437 branch May 30, 2025 20:50
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.

Model.hydrate() TS error: Argument of type 'string' is not assignable to parameter of type 'AnyObject'
3 participants