-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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 necessary
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
9.0.1
Node.js version
N/A
MongoDB server version
N/A
Typescript version (if applicable)
5.0.3
Description
If passing a QueryFilter to the $match type a type error is produced. This is a regression between 9.0.0 and 9.0.1.
Steps to Reproduce
interface FooType {
_id: ObjectId;
date: Date;
}
const fooSchema = new Schema<FooType>({
date: { type: Date, required: true },
});
const FooModel = model<FooType>('foo', fooSchema);
const query: QueryFilter<FooType> = {
date: { $lte: new Date() },
};
await FooModel.aggregate([{ $match: query }]); // No overload matches this callNo overload matches this call.
Overload 1 of 2, '(pipeline?: PipelineStage[] | undefined, options?: AggregateOptions | undefined): Aggregate<any[]>', gave the following error.
Type '_QueryFilter<{ _id: ObjectId; "_id.default": (val: any) => any; "_id.get": (fn: Function) => ObjectId; "_id.schema": Schema<any, Model<any, any, any, any, any, any, any>, ... 8 more ..., {} & ... 1 more ... & { ...; }> | undefined; ... 23 more ...; "_id.validateAll": (validators: (RegExp | ... 1 more ... | Validator...' is not assignable to type '_QueryFilter<Record<string, any>>'.
Type '_QueryFilter<{ _id: ObjectId; "_id.default": (val: any) => any; "_id.get": (fn: Function) => ObjectId; "_id.schema": Schema<any, Model<any, any, any, any, any, any, any>, ... 8 more ..., {} & ... 1 more ... & { ...; }> | undefined; ... 23 more ...; "_id.validateAll": (validators: (RegExp | ... 1 more ... | Validator...' is not assignable to type 'RootFilterOperators<{ [x: string]: any; }>'.
Types of property '$and' are incompatible.
Type 'Filter<{ _id?: ApplyBasicQueryCasting<ObjectId> | undefined; "_id.default"?: ApplyBasicQueryCasting<(val: any) => any> | undefined; ... 25 more ...; "_id.validateAll"?: ApplyBasicQueryCasting<...> | undefined; }>[] | undefined' is not assignable to type 'Filter<{ [x: string]: any; }>[] | undefined'.
Type 'Filter<{ _id?: ApplyBasicQueryCasting<ObjectId> | undefined; "_id.default"?: ApplyBasicQueryCasting<(val: any) => any> | undefined; ... 25 more ...; "_id.validateAll"?: ApplyBasicQueryCasting<...> | undefined; }>[]' is not assignable to type 'Filter<{ [x: string]: any; }>[]'.
Type 'Filter<{ _id?: ApplyBasicQueryCasting<ObjectId> | undefined; "_id.default"?: ApplyBasicQueryCasting<(val: any) => any> | undefined; ... 25 more ...; "_id.validateAll"?: ApplyBasicQueryCasting<...> | undefined; }>' is not assignable to type 'Filter<{ [x: string]: any; }>'.
Type 'Filter<{ _id?: ApplyBasicQueryCasting<ObjectId> | undefined; "_id.default"?: ApplyBasicQueryCasting<(val: any) => any> | undefined; ... 25 more ...; "_id.validateAll"?: ApplyBasicQueryCasting<...> | undefined; }>' is not assignable to type '{ [x: string]: any; _id?: Condition<ObjectId> | undefined; }'.
Types of property '_id' are incompatible.
Type 'Condition<ObjectId | ObjectId[] | null> | undefined' is not assignable to type 'Condition<ObjectId> | undefined'.
Type 'null' is not assignable to type 'Condition<ObjectId> | undefined'.
Overload 2 of 2, '(pipeline: PipelineStage[]): Aggregate<any[]>', gave the following error.
Type '_QueryFilter<{ _id: ObjectId; "_id.default": (val: any) => any; "_id.get": (fn: Function) => ObjectId; "_id.schema": Schema<any, Model<any, any, any, any, any, any, any>, ... 8 more ..., {} & ... 1 more ... & { ...; }> | undefined; ... 23 more ...; "_id.validateAll": (validators: (RegExp | ... 1 more ... | Validator...' is not assignable to type '_QueryFilter<Record<string, any>>'.
Type '_QueryFilter<{ _id: ObjectId; "_id.default": (val: any) => any; "_id.get": (fn: Function) => ObjectId; "_id.schema": Schema<any, Model<any, any, any, any, any, any, any>, ... 8 more ..., {} & ... 1 more ... & { ...; }> | undefined; ... 23 more ...; "_id.validateAll": (validators: (RegExp | ... 1 more ... | Validator...' is not assignable to type 'RootFilterOperators<{ [x: string]: any; }>'.
Types of property '$and' are incompatible.
Type 'Filter<{ _id?: ApplyBasicQueryCasting<ObjectId> | undefined; "_id.default"?: ApplyBasicQueryCasting<(val: any) => any> | undefined; ... 25 more ...; "_id.validateAll"?: ApplyBasicQueryCasting<...> | undefined; }>[] | undefined' is not assignable to type 'Filter<{ [x: string]: any; }>[] | undefined'.
Type 'Filter<{ _id?: ApplyBasicQueryCasting<ObjectId> | undefined; "_id.default"?: ApplyBasicQueryCasting<(val: any) => any> | undefined; ... 25 more ...; "_id.validateAll"?: ApplyBasicQueryCasting<...> | undefined; }>[]' is not assignable to type 'Filter<{ [x: string]: any; }>[]'.
Type 'Filter<{ _id?: ApplyBasicQueryCasting<ObjectId> | undefined; "_id.default"?: ApplyBasicQueryCasting<(val: any) => any> | undefined; ... 25 more ...; "_id.validateAll"?: ApplyBasicQueryCasting<...> | undefined; }>' is not assignable to type 'Filter<{ [x: string]: any; }>'.
Type 'Filter<{ _id?: ApplyBasicQueryCasting<ObjectId> | undefined; "_id.default"?: ApplyBasicQueryCasting<(val: any) => any> | undefined; ... 25 more ...; "_id.validateAll"?: ApplyBasicQueryCasting<...> | undefined; }>' is not assignable to type '{ [x: string]: any; _id?: Condition<ObjectId> | undefined; }'.
Types of property '_id' are incompatible.
Type 'Condition<ObjectId | ObjectId[] | null> | undefined' is not assignable to type 'Condition<ObjectId> | undefined'.
Type 'null' is not assignable to type 'Condition<ObjectId> | undefined'.ts(2769)
Expected Behavior
No type errors, the query's type is valid.
Reactions are currently unavailable
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 necessary