Skip to content

Conversation

@vkarpov15
Copy link
Collaborator

Fix #15902

Summary

Applying mapping types like ApplyBasicCreateCasting tend to confuse TypeScript about assignability: K won't necessarily be assignable to ApplyBasicQueryCasting<Require_id<TRawDocType>>. Easiest fix is to add an override which allows passing partial of TRawDocType to avoid generics headache.

Examples

Copy link
Contributor

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 enhances TypeScript generics support for the create() method by adding direct overloads that accept TRawDocType, bypassing complex mapped types that can confuse TypeScript's assignability checking. This specifically addresses issue #15902 where generic type parameters couldn't be proven assignable to DeepPartial<ApplyBasicCreateCasting<Require_id<TRawDocType>>>.

Key Changes:

  • Added two new create() overloads accepting TRawDocType directly (single doc and array)
  • Added type test demonstrating the fix for generic wrapper classes

Reviewed changes

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

File Description
types/models.d.ts Added two new create() overloads for TRawDocType (single and array) to support better generic type inference
test/types/create.test.ts Added type test with generic class wrapper to verify the fix works for issue #15902

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Collaborator

@AbdelrahmanHafez AbdelrahmanHafez left a comment

Choose a reason for hiding this comment

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

LGTM.
Heads up, this PR has the changes d96c183 from #15904.

@hasezoey hasezoey added the typescript Types or Types-test related issue / Pull Request label Dec 18, 2025
@vkarpov15 vkarpov15 merged commit 6b271b3 into master Dec 19, 2025
27 checks passed
@hasezoey hasezoey deleted the vkarpov15/gh-15902 branch December 20, 2025 11:08
@vkarpov15 vkarpov15 modified the milestones: 9.0.3, 9.1 Dec 30, 2025
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.

mongoose@9: No overload matches this call - await this.model.create(resource)

4 participants