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

Investigate NODE-4494 - Filter / UpdateFilter do not infer the correct type of Record values

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

      NODE-4494 Description

      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:
            bailey.pearson@mongodb.com Bailey Pearson
            Reporter:
            dbeng-pm-bot PM Bot
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: