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): screenshot from mongodb.d.ts file - 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