-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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.19.0
Node.js version
22
MongoDB server version
6
Typescript version (if applicable)
5.7.3
Description
I have a generic helper function that adds text search, sorting, and pagination to any query.
Since version 8.19.0, it has been throwing an error on $text.
No overload matches this call. Overload 1 of 4, '(filter: RootFilterQuery<T>, projection?: ProjectionType<T> | null | undefined, options?: QueryOptions<T> | null | undefined): QueryWithHelpers<...>', gave the following error. Object literal may only specify known properties, and '$text' does not exist in type 'Query<any, any, {}, unknown, "find", Record<string, never>> | ObjectId'. Overload 2 of 4, '(filter: RootFilterQuery<T>, projection?: ProjectionType<T> | null | undefined): QueryWithHelpers<T[], T, object, T, "find", Record<string, never>>', gave the following error. Object literal may only specify known properties, and '$text' does not exist in type 'Query<any, any, {}, unknown, "find", Record<string, never>> | ObjectId'. Overload 3 of 4, '(filter: RootFilterQuery<T>): QueryWithHelpers<T[], T, object, T, "find", Record<string, never>>', gave the following error. Object literal may only specify known properties, and '$text' does not exist in type 'Query<any, any, {}, unknown, "find", Record<string, never>> | ObjectId'.ts(2769)
Steps to Reproduce
type QueryFeaturesProps = {
params: Partial<DefaultQuery>;
};
export const queryFeatures = async <T, R, TQueryOp>(
query: Query<R, T, object, T, TQueryOp>,
{ params }: QueryFeaturesProps
): Promise<{ content: GetLeanResultType<T, R, TQueryOp>; result: number }> => {
if (params.search) {
query.find({
$text: {
$search: params.search,
},
});
}
...
return {
content,
result,
};
};Expected Behavior
There were no type errors before version 8.19.0.