Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion test/types/PipelineStage.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ObjectId } from 'mongodb';
import type { PipelineStage } from 'mongoose';
import type { PipelineStage, QueryFilter } from 'mongoose';

/**
* $addFields:
Expand Down Expand Up @@ -574,3 +574,21 @@ const vectorSearchStages: PipelineStage[] = [
}
}
];

function gh16006() {
interface MyDoc {
_id: string;
name: string;
}

const matchCriteria: QueryFilter<MyDoc> = {
_id: 'foobar',
name: 'test'
};

const pipeline: PipelineStage[] = [
{
$match: matchCriteria
}
];
}
23 changes: 0 additions & 23 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -945,29 +945,6 @@ declare module 'mongoose' {
: BufferToBinary<T[K]>;
} : T;

/**
* Converts any UUID properties into strings for JSON serialization
*/
export type UUIDToJSON<T> = T extends Types.UUID
? string
: T extends mongodb.UUID
? string
: T extends Document
? T
: T extends TreatAsPrimitives
? T
: T extends Record<string, any> ? {
[K in keyof T]: T[K] extends Types.UUID
? string
: T[K] extends mongodb.UUID
? string
: T[K] extends Types.DocumentArray<infer ItemType>
? Types.DocumentArray<UUIDToJSON<ItemType>>
: T[K] extends Types.Subdocument<unknown, unknown, infer SubdocType>
? HydratedSingleSubdocument<UUIDToJSON<SubdocType>>
: UUIDToJSON<T[K]>;
} : T;

/**
* Converts any UUID properties into strings for JSON serialization
*/
Expand Down
14 changes: 12 additions & 2 deletions types/query.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,18 @@ declare module 'mongoose' {

export type ApplyBasicQueryCasting<T> = QueryTypeCasting<T> | QueryTypeCasting<T[]> | (T extends (infer U)[] ? QueryTypeCasting<U> : T) | null;

type _QueryFilter<T> = ({ [P in keyof T]?: mongodb.Condition<ApplyBasicQueryCasting<T[P]>>; } & mongodb.RootFilterOperators<{ [P in keyof mongodb.WithId<T>]?: ApplyBasicQueryCasting<mongodb.WithId<T>[P]>; }>);
type QueryFilter<T> = IsItRecordAndNotAny<T> extends true ? _QueryFilter<WithLevel1NestedPaths<T>> : _QueryFilter<Record<string, any>>;
type _QueryFilter<T> = (
{ [P in keyof T]?: mongodb.Condition<ApplyBasicQueryCasting<T[P]>>; } &
mongodb.RootFilterOperators<{ [P in keyof mongodb.WithId<T>]?: ApplyBasicQueryCasting<mongodb.WithId<T>[P]>; }>
);
type _QueryFilterLooseId<T> = (
{ [P in keyof T]?: mongodb.Condition<ApplyBasicQueryCasting<T[P]>>; } &
mongodb.RootFilterOperators<
{ [P in keyof T]?: ApplyBasicQueryCasting<T[P]>; } &
{ _id?: any; }
>
);
type QueryFilter<T> = IsItRecordAndNotAny<T> extends true ? _QueryFilter<WithLevel1NestedPaths<T>> : _QueryFilterLooseId<Record<string, any>>;

type MongooseBaseQueryOptionKeys =
| 'context'
Expand Down
Loading