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

Investigate NODE-4481 - Filter / UpdateFilter does not check nested properties in optional objects

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

      NODE-4481 Description

      What problem are you facing?

      Both `Filter` and `UpdateFilter` types check top-level optional (nullable) properties, but they don't check nested properties inside a top-level optional (nullable) object property.

      What driver and relevant dependency versions are you using?

      • mongodb v4.8.1
      • typescript v4.7.4

      Steps to reproduce?

      Unable to find source-code formatter for language: typescript. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      import { Filter, UpdateFilter } from 'mongodb';
      
      interface Foo {
        optional?: string;
        optionalNested?: {
          path: string;
        };
        required: string;
        requiredNested: {
          path: string;
        };
      }
      
      const queryOptionalOK: Filter<Foo> = { optional: "foo", "optionalNested.path": "foo" };
      // ^ OK
      const queryOptionalFail: Filter<Foo> = { optional: 1, "optionalNested.path": 1 };
      // ^ Fail - TS flags only `optional`, but `optionalNested.path` should also be flagged
      const queryRequiredOK: Filter<Foo> = { required: "foo", "requiredNested.path": "foo" };
      // ^ OK
      const queryRequiredFail: Filter<Foo> = { required: 1, "requiredNested.path": 1 };
      // ^ OK - Both fields are flagged
      
      const updateOptionalOK: UpdateFilter<Foo> = { $set: { optional: "foo", "optionalNested.path": "foo" } };
      // ^ OK - Expected
      const updateOptionalFail: UpdateFilter<Foo> = { $set: { optional: 1, "optionalNested.path": 1 } };
      // ^ Fail - TS flags only `optional`, but `optionalNested.path` should also be flagged
      const updateRequiredOK: UpdateFilter<Foo> = { $set: { required: "foo", "requiredNested.path": "foo" } };
      // ^ OK - Expected
      const updateRequiredFail: UpdateFilter<Foo> = { $set: { required: 1, "requiredNested.path": 1 } };
      // ^ OK - Both fields are flagged
      

      TS Playground

            Assignee:
            durran.jordan@mongodb.com Durran Jordan
            Reporter:
            dbeng-pm-bot PM Bot
            Durran Jordan
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: