-
Type: Task
-
Resolution: Fixed
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
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
- is depended on by
-
NODE-4481 Filter / UpdateFilter does not check nested properties in optional objects
- Closed