-
Type: Task
-
Resolution: Done
-
Priority: Unknown
-
None
-
Affects Version/s: None
-
Component/s: None
-
Labels:
-
Empty show more show less
-
Not Needed
NODE-4095 Description
See https://www.mongodb.com/community/forums/t/mongodb-4-1-4-with-typescript-findone-syntax-error-type-void-is-not-assignable-to-type-dbuser-undefined-ts-2322/131533
The reason for this is when you write some generic code, e.g. something like
function findSomeThings<TSchema>(collection: Collection<TSchema>):Promise<TSchema> { const filter = {} as Filter<TSchema>; return collection.findOne(filter); }
the overload with Callback is picked. This might be unintuitive but it's because Filter overlaps with Callback as types as Filter can just be Partial<T> with equals Partial<any> = any in this code. Thus I suggest reordering those overloads. The other scenario seems unlikely to kick in, as something typed to Callback<WithId<T>> would still resolve to the right overload even if the Filter one comes first
- is depended on by
-
NODE-4095 TypeScript: wrong findOne overload often picked
- Closed