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

TypeScript error on `Filter` on 4.3.1

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
    • 0
    • Not Needed

      What problem are you facing?

      Project fails to compile after upgrade to 4.3.1.

      What driver and relevant dependency versions are you using?

      mongodb 4.3.1

      Typescript 4.5.5

      Steps to reproduce?

      The following code

      interface User {
        _id: string;
        name: string;
      }
      
      function stringFilter(q: unknown): Filter<User> {
        const query: Filter<User> = {};
        if (q && typeof q === "string") {
          query.$text = {
            $search: q,
            $caseSensitive: false,
            $diacriticSensitive: false,
            $language: "en",
          };
        }
        return query;
      }
      
      const query = stringFilter("search");
      let results = collection.find(query);
      

      gives the error "Property '$text' does not exist on type 'Filter<User>'. Property '$text' does not exist on type 'Partial<User>'."

      It worked on 4.3.0.

            Assignee:
            bailey.pearson@mongodb.com Bailey Pearson
            Reporter:
            chris.midgley@newredo.com Chris Midgley
            Bailey Pearson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: