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

Investigate NODE-3856 - Can not use a TypeScript interface as a filter with embeded array

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • 1
    • Not Needed

      NODE-3856 Description

      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:
            dbeng-pm-bot PM Bot
            Bailey Pearson
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: