-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Closed
Labels
helpThis issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessaryThis issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessarytypescriptTypes or Types-test related issue / Pull RequestTypes or Types-test related issue / Pull Request
Milestone
Description
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Mongoose version
8.2.3
Node.js version
20
MongoDB server version
7.0.6
Typescript version (if applicable)
5.4.3
Description
Repro Script throws
No overload matches this call.
Overload 1 of 5, '(filter: FilterQuery<ModelType>, projection?: ProjectionType<ModelType> | null | undefined, options?: QueryOptions<ModelType> | null | undefined): Query<...>', gave the following error.
Argument of type '{ _id: string | Types.ObjectId; }' is not assignable to parameter of type 'FilterQuery<ModelType>'.
Type '{ _id: string | Types.ObjectId; }' is not assignable to type '{ [P in keyof ModelType]?: Condition<ModelType[P]> | undefined; }'.
Overload 2 of 5, '(filter: FilterQuery<ModelType>, projection?: ProjectionType<ModelType> | null | undefined): Query<IfAny<ModelType, any, Document<...> & Require_id<...>>[], IfAny<...>, {}, ModelType, "find">', gave the following error.
Argument of type '{ _id: string | Types.ObjectId; }' is not assignable to parameter of type 'FilterQuery<ModelType>'.
Type '{ _id: string | Types.ObjectId; }' is not assignable to type '{ [P in keyof ModelType]?: Condition<ModelType[P]> | undefined; }'.
Overload 3 of 5, '(filter: FilterQuery<ModelType>): Query<IfAny<ModelType, any, Document<unknown, {}, ModelType> & Require_id<ModelType>>[], IfAny<...>, {}, ModelType, "find">', gave the following error.
Argument of type '{ _id: string | Types.ObjectId; }' is not assignable to parameter of type 'FilterQuery<ModelType>'.
Type '{ _id: string | Types.ObjectId; }' is not assignable to type '{ [P in keyof ModelType]?: Condition<ModelType[P]> | undefined; }'.ts(2769)
Steps to Reproduce
import { Model, Types } from "mongoose";
function findById<ModelType extends {_id: Types.ObjectId | string}>(model: Model<ModelType>, _id: Types.ObjectId | string){
return model.find({_id: _id})
}
Expected Behavior
No Error
a88zach, ghost91-, Pharb, vypham0209, Talb2005 and 5 more
Metadata
Metadata
Assignees
Labels
helpThis issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessaryThis issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessarytypescriptTypes or Types-test related issue / Pull RequestTypes or Types-test related issue / Pull Request