-
Type:
Task
-
Resolution: Done
-
Priority:
Unknown
-
None
-
Affects Version/s: None
-
Component/s: None
NODE-4305 Description
What problem are you facing?
When using a generic type, the type of `Filter` seems to break down. This seems to be isolated to when using a generic type, as "hardcoding" the type works fine.
What driver and relevant dependency versions are you using?
"mongodb": "4.7.0"
"typescript": "4.6.4"
Steps to reproduce?
async function demo<T extends { foo: string }>() { const client = await MongoClient.connect('mongodb://xyz'); const col = client.db().collection<T>('foo'); col.findOne({ foo: 'foo' }); }
Results in
TS2769: No overload matches this call. The last overload gave the following error. Argument of type '{ foo: "foo"; }' is not assignable to parameter of type 'Filter<T>'. Type '{ foo: "foo"; }' is not assignable to type '{ [Property in Join<NestedPaths<WithId<T>>, ".">]?: Condition<PropertyType<WithId<T>, Property>> | undefined; } & RootFilterOperators<...>'. Type '{ foo: "foo"; }' is not assignable to type '{ [Property in Join<NestedPaths<WithId<T>>, ".">]?: Condition<PropertyType<WithId<T>, Property>> | undefined; }'.
Whereas "hardcoding" the type works fine
async function demo<>() { const client = await MongoClient.connect('mongodb://xyz'); const col = client.db().collection<{ foo: string }>('foo'); col.findOne({ foo: 'foo' }); }
Oddly enough, autocomplete seems to provide the correct type for "foo":
- is depended on by
-
NODE-4305 Generic type cannot be used in Filter
-
- Closed
-