types(create): fix handling of nested objects typed as interfaces - #16363
Merged
Conversation
Contributor
There was a problem hiding this comment.
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. |
AbdelrahmanHafez
approved these changes
Jul 5, 2026
Collaborator
|
Probably worth addressing Copilot's comment, otherwise LGTM |
hasezoey
approved these changes
Jul 6, 2026
hasezoey
left a comment
Collaborator
There was a problem hiding this comment.
Looks good to me and fixes the issue in typegoose-testing.
I also agree that the Copilot comment should be addressed.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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,Nestedis an interface not an object type, and interfaces are not assignable toRecord<string, unknown>for TypeScript internal reasons. Probably because interfaces can be augmented (multiple definitions of the same interface add properties).Examples