Skip to content

types(query): allow assigning QueryFilter<DocType> to QueryFilter<any>#16020

Merged
vkarpov15 merged 1 commit intomasterfrom
vkarpov15/gh-16006
Feb 11, 2026
Merged

types(query): allow assigning QueryFilter<DocType> to QueryFilter<any>#16020
vkarpov15 merged 1 commit intomasterfrom
vkarpov15/gh-16006

Conversation

@vkarpov15
Copy link
Collaborator

Fix #16006

Summary

The problem in #16006 is that WithId<> in QueryFilter<any> makes QueryFilter<any> act like a query filter with _id: ObjectId, which is potentially problematic because you would intuitively assume that QueryFilter<{ _id: string }> is assignable to QueryFilter<any>.

I also removed a duplicate UUIDToJSON definition

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 adjusts Mongoose’s TypeScript query filter typings so that QueryFilter<DocType> (including document types with non-ObjectId _id, like string) is assignable to places that accept QueryFilter<any> (notably aggregation $match), addressing #16006.

Changes:

  • Introduces a “looser _id” variant for QueryFilter<any> to avoid mongodb.WithId<any> forcing _id: ObjectId.
  • Removes a duplicate UUIDToJSON type definition in types/index.d.ts.
  • Adds a type-level regression case covering $match accepting QueryFilter for a document with string _id.

Reviewed changes

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

File Description
types/query.d.ts Adjusts the QueryFilter<any> fallback to avoid _id being forced to ObjectId, improving assignability.
types/index.d.ts Removes a duplicate UUIDToJSON type definition, leaving the canonical alias-based definition.
test/types/PipelineStage.test.ts Adds a compile-time regression case for #16006 using $match with QueryFilter<MyDoc> where _id: string.

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 👍

@AbdelrahmanHafez AbdelrahmanHafez added the typescript Types or Types-test related issue / Pull Request label Feb 10, 2026
@vkarpov15 vkarpov15 merged commit 324ff4c into master Feb 11, 2026
11 checks passed
@hasezoey hasezoey deleted the vkarpov15/gh-16006 branch February 11, 2026 16:19
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.

TypeScript Error: FilterQuery with string _id not assignable to PipelineStage $match in Mongoose 9.1.5

4 participants