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

Can not use a TypeScript interface as a filter with embeded array

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Blocker - P1 Blocker - P1
    • 4.3.1
    • Affects Version/s: None
    • Component/s: None
    • 1
    • Not Needed

      What problem are you facing?

      With last version including "Type inference for nested documents", findOne (and many other functions) does not accept an interface as a filter if it contains an array.

      What driver and relevant dependency versions are you using?

      mongodb@4.3.0

      Steps to reproduce?

      export interface S

      { readonly a: readonly string[] }

      const obj =

      { a: [''] }

      ;
      (await ((await getClient()).db('db').collection<S>('col').updateOne(obj as unknown as S, { $set:

      { a: [''] }

      })));
      => TypeScript error Argument of type 'S' is not assignable to parameter of type 'Filter<S>'.
      Type 'S' is not assignable to type '{ [x: `a.${number}`]: Condition<string> | undefined; _id?: Condition<ObjectId>; }'.
      Index signature for type '`a.${number}`' is missing in type 'S'.ts(2345)

      (await ((await getClient()).db('db').collection<S>('col').updateOne(obj, { $set:

      { a: [''] }

      })));
      => No TypeScript error, here obj is an object, not an interface

            Assignee:
            bailey.pearson@mongodb.com Bailey Pearson
            Reporter:
            js@stairwage.com Jérôme Senot
            Daria Pardue
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: