Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-4956

Filter<TSchema> type is too restrictive due to unnecessary union with Partial<TSchema>

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: 4.13.0
    • Component/s: TypeScript
    • 2
    • Not Needed
    • Not Needed

      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

        1. image-2023-01-14-16-18-48-131.png
          90 kB
          Jack Parkinson
        2. image-2023-01-14-16-19-27-416.png
          90 kB
          Jack Parkinson

            Assignee:
            bailey.pearson@mongodb.com Bailey Pearson
            Reporter:
            jack.parkinson@scraye.com Jack Parkinson
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: