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(document): make sure toObject() and toJSON() apply versionKey __v #15097

Merged
merged 2 commits into from
Dec 16, 2024

Conversation

vkarpov15
Copy link
Collaborator

Fix #15077

Summary

#15077 points out that lean() and toObject() should return compatible types, but currently do not due to __v

Examples

@vkarpov15 vkarpov15 added this to the 8.9.1 milestone Dec 15, 2024
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, though cases some expected type test failures in typegoose.
Maybe consider putting this into the next minor version.

The errors for context
fail ./test/tests/types/basicTypegoose.test-d.ts

Error: Type 'SomeClass & { _id: ObjectId; } & { __v: number; }' is not identical to type 'SomeClass & { _id: ObjectId; } & Required<{ _id: ObjectId; }>'.

  275 | 
  276 |   expect(toobj).type.toBe<
  277 |     SomeClass & { _id: typegoose.mongoose.Types.ObjectId } & Required<{
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  278 |         _id: typegoose.mongoose.Types.ObjectId;
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  279 |       }>
      | ~~~~~~~~
  280 |   >();

        at ./test/tests/types/basicTypegoose.test-d.ts:277:5

Error: Type 'FlattenMaps<SomeClass & { _id: ObjectId; } & { __v: number; }>' is not identical to type 'FlattenMaps<SomeClass & { _id: ObjectId; }>'.

  279 |       }>
  280 |   >();
  281 |   expect(tojson).type.toBe<typegoose.mongoose.FlattenMaps<SomeClass & { _id: typegoose.mongoose.Types.ObjectId }>>();
      |                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  282 | }
  283 | 
  284 | gh732();

        at ./test/tests/types/basicTypegoose.test-d.ts:281:28

@hasezoey hasezoey added the typescript Types or Types-test related issue / Pull Request label Dec 16, 2024
@vkarpov15
Copy link
Collaborator Author

Merging into 8.10 branch.

@vkarpov15 vkarpov15 merged commit f8844bb into 8.10 Dec 16, 2024
5 checks passed
@hasezoey hasezoey deleted the vkarpov15/gh-15077 branch December 16, 2024 17:58
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.create does not have a lean option, and using toObject and toJSON does not produce similar typing
2 participants