Skip to content

Conversation

@vkarpov15
Copy link
Collaborator

@vkarpov15 vkarpov15 commented Nov 17, 2025

Summary

Fix #15693

Model.schema currently is a generic schema rather than TSchema, and ThisParameter<T[K], unknown> extends unknown is trivially true because everything extends unknown.

Examples

@vkarpov15 vkarpov15 added this to the 8.20.1 milestone Nov 17, 2025
Copilot finished reviewing on behalf of vkarpov15 November 17, 2025 18:25
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 fixes two type issues in Mongoose:

  1. Corrects the Model.schema property type to use the more specific TSchema generic parameter instead of Schema<TRawDocType>
  2. Fixes a bug in the AddThisParameter utility type where ThisParameter<T[K], unknown> extends unknown was always true, preventing proper detection of explicit this parameters in schema methods

Reviewed Changes

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

File Description
types/utility.d.ts Replaces IfUnknown helper with IsUnknown that returns boolean literal types, and fixes the AddThisParameter type to properly check if a function already has an explicit this parameter before injecting one
types/models.d.ts Changes Model.schema property type from Schema<TRawDocType> to TSchema to preserve the full schema type information
test/types/models.test.ts Adds test case demonstrating that methods with explicit this parameters preserve their type while methods without get the hydrated document type injected

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

@hasezoey hasezoey added the typescript Types or Types-test related issue / Pull Request label Nov 18, 2025
@vkarpov15 vkarpov15 merged commit f631093 into master Nov 20, 2025
11 checks passed
@hasezoey hasezoey deleted the vkarpov15/gh-15693 branch November 20, 2025 20:33
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.

Instance methods on Document does not allow setting this type explicitly

3 participants