Skip to content

types(create): fix handling of nested objects typed as interfaces - #16363

Merged
vkarpov15 merged 2 commits into
masterfrom
vkarpov15/gh-16362
Jul 6, 2026
Merged

types(create): fix handling of nested objects typed as interfaces#16363
vkarpov15 merged 2 commits into
masterfrom
vkarpov15/gh-16362

Conversation

@vkarpov15

Copy link
Copy Markdown
Collaborator

Summary

#16362 is not an issue with strings vs objectids, it's an issue with how nested object types vs nested interfaces are handled by create() typing. In #16362, Nested is an interface not an object type, and interfaces are not assignable to Record<string, unknown> for TypeScript internal reasons. Probably because interfaces can be augmented (multiple definitions of the same interface add properties).

Examples

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 Mongoose’s TypeScript Model.create() input casting types to correctly handle nested subdocuments whose types are declared as interfaces (as in #16362), and adds a corresponding type-level test.

Changes:

  • Adjust CreateObjectWithExtraKeys<T> to accept both interface-typed values and “extra key” object-literals used in create inputs.
  • Add a type test covering nested populated doc creation via create().

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.

File Description
types/models.d.ts Updates the helper type used by ApplyBasicCreateCasting for create() inputs to better support nested interface-typed objects.
test/types/create.test.ts Adds a type test scenario for nested populated doc creation inputs.

Comment thread test/types/create.test.ts
@AbdelrahmanHafez

Copy link
Copy Markdown
Collaborator

Probably worth addressing Copilot's comment, otherwise LGTM

@hasezoey hasezoey left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good to me and fixes the issue in typegoose-testing.
I also agree that the Copilot comment should be addressed.

@hasezoey hasezoey added the typescript Types or Types-test related issue / Pull Request label Jul 6, 2026
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@vkarpov15 vkarpov15 added this to the 9.7.4 milestone Jul 6, 2026
@vkarpov15
vkarpov15 merged commit 4d2b1c5 into master Jul 6, 2026
5 checks passed
@AbdelrahmanHafez
AbdelrahmanHafez deleted the vkarpov15/gh-16362 branch July 6, 2026 21:27
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.

4 participants