Details
-
Task
-
Status: Closed
-
Major - P3
-
Resolution: Fixed
-
None
-
None
-
None
Description
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?
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
|
Attachments
Issue Links
- is depended on by
-
NODE-4481 Filter / UpdateFilter does not check nested properties in optional objects
-
- Closed
-