diff --git a/types/query.d.ts b/types/query.d.ts index 44d9a71062f..5784987882d 100644 --- a/types/query.d.ts +++ b/types/query.d.ts @@ -115,8 +115,9 @@ declare module 'mongoose' { /** @see https://www.mongodb.com/docs/manual/reference/operator/query/comment/#op._S_comment */ $comment?: string; // we could not find a proper TypeScript generic to support nested queries e.g. 'user.friends.name' - // this will mark all unrecognized properties as any (including nested queries) - [key: string]: any; + // this will mark all unrecognized properties as any (including nested queries) only if + // they include a "." (to avoid generically allowing any unexpected keys) + [nestedSelector: `${string}.${string}`]: any; }; interface QueryTimestampsConfig {