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

Filter / UpdateFilter do not infer the correct type of Record values

      What problem are you facing?

      `Filter` and `UpdateFilter` do not infer the correct type of `Record` values.

      What driver and relevant dependency versions are you using?

      • mongodb v4.8.1
      • typescript v4.7.4

      Steps to reproduce?

      import { Filter, PropertyType, UpdateFilter } from 'mongodb';
      
      interface Foo {
        data: Record<string, boolean>;
      }
      
      const queryOK: Filter<Foo> = { "data.path": true };
      // ^ OK
      const queryFail: Filter<Foo> = { "data.path": 1 };
      // ^ Fail - TS does not flag the wrong type of `data.path`
      
      const updateOK: UpdateFilter<Foo> = { $set: { "data.path": true } };
      // ^ OK - Expected
      const updateFail: UpdateFilter<Foo> = { $set: { "data.path": 1 } };
      // ^ Fail - TS does not flag the wrong type of `data.path`
      
      type DataValueType = PropertyType<Foo, `data.${string}`>;
      // ^ `unknown` - should be `boolean`
      

      TS Playground

            Assignee:
            Unassigned Unassigned
            Reporter:
            avaly@plexapp.com Valentin Agachi
            Votes:
            3 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: