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

Investigate NODE-3904 - Consider preferring safety of existing types over compatibility with future operators

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • 0
    • Not Needed

      NODE-3904 Description
      In https://github.com/mongodb/node-mongodb-native/pull/3115 I proposed removing support for arbitrary keys from the `RootFilterOperators<TSchema>` type. It turns out that this was added by design:

      The reason we have RootFilterOperators extend Document is so that any driver version can be forwards compatible with new query operators that are continually being added to the server

      source: https://github.com/mongodb/node-mongodb-native/pull/3115#issuecomment-1021303302

       

      I'd like to advocate for a change in this design decision. This reduces the type safety of the existing queries, as unknown operators (or typos of real operators) can no longer be caught by the type system, in service of future users who want to use a new feature of the database without upgrading their Node driver.

      If we did switch to stricter-types, such users who do want to start using new operators would be able to opt-out of stricter type checking: they can annotate their queries using operators unknown to their driver version with `@ts-expect-error`.

      If we don't implement the stricter type checks in the driver, existing users can not opt-in to stronger type checks. (Technically we do export enough of the types that a user could create their own versions of `RootFilterOperators<TSchema>` and `Filter<TSchema>` that are stricter but still assignable to the types shipped with the driver, but this is a lot of extra burden for the folks who want maximum correctness).

      Thank you for considering this alternate point of view!

            Assignee:
            Unassigned Unassigned
            Reporter:
            dbeng-pm-bot PM Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: