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

    XMLWordPrintableJSON

Details

    • Task
    • Status: Closed
    • Major - P3
    • Resolution: Done
    • None
    • None
    • None
    • 2
    • Not Needed

    Description

      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

      Attachments

        Issue Links

          Activity

            People

              bailey.pearson@mongodb.com Bailey Pearson
              dbeng-pm-bot PM Bot
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: