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

Consider preferring safety of existing types over compatibility with future operators

    • Type: Icon: Question Question
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None

      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:
            noah@hustle.life Noah Silas
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: