Tom_Keidar
(Tom Keidar)
November 9, 2021, 1:56pm
1
Hey all,
I’m using mongodb client 4.1.4 with typescript and having a weird ts error on a code that used to work fine.
Here is a code sample:
async function getUser(): Promise<DBUser | undefined> {
const filter: Filter<DBUser> = { apiKey: '123' }
return collection.findOne(filter)
}
That’s the error on vscode:
Type 'void' is not assignable to type 'DBUser | undefined'.ts(2322)
(method) Collection<Document>.findOne(callback: Callback<Document | null>): void (+10 overloads)
and the definition of findOne in mongodb.d.ts (version 4.1.4):
It seems like it “uses” a wrong overload of the findOne function which returns void instead of the one which returns a promise.
What am I doing wrong and how can I fix that?
tnx
1 Like
experiencing the same thing
https://jira.mongodb.org/browse/NODE-4095
mongodb:main
← staeke:NODE-4095/findOne-overload-fix
opened 05:34PM - 17 Mar 22 UTC
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
### Description
Fix of https://jira.mongodb.org/browse/NODE-4095
#### What is changing?
Reorders single parameter overloads of findOne to pick the `Filter` one in generic consumer code
##### Is there new documentation needed for these changes?
no
#### What is the motivation for this change?
The JIRA issue (and community ticket) outlines scenairos that imho should work
### Double check the following
- [X] Ran `npm run check:lint` script
- [X] Self-review completed using the [steps outlined here](https://github.com/mongodb/node-mongodb-native/blob/HEAD/CONTRIBUTING.md#reviewer-guidelines)
- [X] PR title follows the correct format: `<type>(NODE-xxxx)<!>: <description>`
- [ ] Changes are covered by tests
- [X] New TODOs have a related JIRA ticket