-
Type: Bug
-
Resolution: Works as Designed
-
Priority: Unknown
-
None
-
Affects Version/s: 4.13.0
-
Component/s: TypeScript
What problem are you facing?
`Filter` type includes an unnecessary union with `Partial<TSchema>` which makes breaks simple use cases such as defining an empty filter and populating the fields within it based on conditions. See below.
This change seems to have been introduced in 4.3.1 according to this ticket:
https://jira.mongodb.org/browse/NODE-3936
Alas, the change was not reverted as it should have been because the union is not necessary–`Filter` already worked for the use case that `Partial<TSchema>` was introduced for. Again, see below.
I have tried using workarounds involving `RootFilterOperators` but they do not work well and frequently cause type errors that force the use of `@ts-expect-error` to disable typescript, such as this one:
// @ts-expect-error Type instantiation is excessively deep and possibly infinite.
The solution is fortunately simple: remove `Partial<TSchema>` from the `Filter` type.
What driver and relevant dependency versions are you using?
mongodb 4.13.0
Steps to reproduce?
Filter from 4.3.0
Filter from 4.13.0
- is related to
-
NODE-3936 TypeScript error on `Filter` on 4.3.1
- Closed