Skip to content

Commit

Permalink
fix(index.d.ts): backport streamlining of FilterQuery and DocumentDef…
Browse files Browse the repository at this point in the history
…inition to avoid "excessively deep and possibly infinite" TS errors

Fix #10617
  • Loading branch information
vkarpov15 committed Oct 14, 2021
1 parent 4b8e0d1 commit f1376f3
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions index.d.ts
Expand Up @@ -2524,15 +2524,9 @@ declare module 'mongoose' {
}

type _FilterQuery<T> = {
[P in keyof T]?: P extends '_id'
? [Extract<T[P], mongodb.ObjectId>] extends [never]
? mongodb.Condition<T[P]>
: mongodb.Condition<T[P] | string | { _id: mongodb.ObjectId }>
: [Extract<T[P], mongodb.ObjectId>] extends [never]
? mongodb.Condition<T[P]>
: mongodb.Condition<T[P] | string>;
[P in keyof T]?: mongodb.Condition<[Extract<T[P], mongodb.ObjectId>] extends [never] ? T[P] : T[P] | string>;
} &
mongodb.RootQuerySelector<DocumentDefinition<T>>;
mongodb.RootQuerySelector<T>;

export type FilterQuery<T> = _FilterQuery<T>;

Expand Down Expand Up @@ -2589,14 +2583,14 @@ declare module 'mongoose' {

export type UpdateQuery<T> = (_UpdateQuery<_UpdateQueryDef<T>> & mongodb.MatchKeysAndValues<_UpdateQueryDef<LeanDocument<T>>>);

type _AllowStringsForIds<T> = {
[K in keyof T]: [Extract<T[K], mongodb.ObjectId>] extends [never]
export type DocumentDefinition<T> = {
[K in keyof Omit<T, Exclude<keyof Document, '_id' | 'id' | '__v'>>]:
[Extract<T[K], mongodb.ObjectId>] extends [never]
? T[K] extends TreatAsPrimitives
? T[K]
: _AllowStringsForIds<T[K]>
: LeanDocumentElement<T[K]>
: T[K] | string;
};
export type DocumentDefinition<T> = _AllowStringsForIds<LeanDocument<T>>;

type actualPrimitives = string | boolean | number | bigint | symbol | null | undefined;
type TreatAsPrimitives = actualPrimitives |
Expand Down

0 comments on commit f1376f3

Please sign in to comment.