-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FilterQuery Typing fails for generic type #14459
Comments
Error comes from v8.2.3. |
related to #14462 |
Looks like OP's script fails to compile with TypeScript 5.4.3:
I think this is just a limitation of TypeScript, because
We will take a quick look to see if there's some way we can work around this weird |
I took a look but there's nothing we can do other than 1) make import { Model, Types, model, Schema, FilterQuery } from "mongoose";
function findById<ModelType extends {_id: Types.ObjectId | string}>(model: Model<ModelType>, _id: Types.ObjectId | string){
return model.find({_id: _id} as FilterQuery<ModelType>);
} This is suboptimal, but unfortunately a limitation of TypeScript. From this SO answer: "Never assign a concrete type to a generic type parameter, consider it as read-only!". That includes calling a function with arguments that rely on the generic type parameter. Even if we make Given that |
Fixed by #14510 |
Prerequisites
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
Steps to Reproduce
Expected Behavior
No Error
The text was updated successfully, but these errors were encountered: