diff --git a/src/mongo_types.ts b/src/mongo_types.ts index 83bf11ad6a5..9ac485b1a90 100644 --- a/src/mongo_types.ts +++ b/src/mongo_types.ts @@ -65,13 +65,15 @@ export type EnhancedOmit = string extends keyof TRecor export type WithoutId = Omit; /** A MongoDB filter can be some portion of the schema or a set of operators @public */ -export type Filter = +export type Filter = ( | Partial - | ({ + | { [Property in Join>, '.'>]?: Condition< PropertyType, Property> >; - } & RootFilterOperators>); + } +) & + RootFilterOperators>; /** @public */ export type Condition = AlternativeType | FilterOperators>; diff --git a/test/types/community/collection/findX-recursive-types.test-d.ts b/test/types/community/collection/findX-recursive-types.test-d.ts index 96c4e095cce..731fb844a09 100644 --- a/test/types/community/collection/findX-recursive-types.test-d.ts +++ b/test/types/community/collection/findX-recursive-types.test-d.ts @@ -1,6 +1,6 @@ import { expectError } from 'tsd'; -import type { Collection } from '../../../../src'; +import type { Collection, Filter } from '../../../../src'; /** * mutually recursive types are not supported and will not get type safety diff --git a/test/types/community/collection/findX.test-d.ts b/test/types/community/collection/findX.test-d.ts index 463ba1518e7..04db3987c1a 100644 --- a/test/types/community/collection/findX.test-d.ts +++ b/test/types/community/collection/findX.test-d.ts @@ -313,6 +313,16 @@ const fooObj: Foo = { // eslint-disable-next-line @typescript-eslint/no-unused-vars const fooFilter: Filter = fooObj; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const fooFilterBuiltNow: Filter = { + a: 'foo', + $or: [{ a: 'bar' }] +}; + +const fooFilterBuiltLater: Filter = {}; +fooFilterBuiltLater.a = 'foo'; +fooFilterBuiltLater.$or = [{ a: 'bar' }]; + // Specifically test that arrays can be included as a part of an object // ensuring that a bug reported in https://jira.mongodb.org/browse/NODE-3856 is addressed interface FooWithArray {