seald / nedb

The JavaScript Database, for Node.js, nw.js, electron and the browser
MIT License
351 stars 32 forks source link

Wrong generic type for findAsync method #57

Open dremchee opened 4 months ago

dremchee commented 4 months ago

https://github.com/seald/nedb/blob/68279ccdf09fd3064ce5e02e0f3c30d75d8e2cfa/index.d.ts#L91

I think it should be like this Document<T>[] instead of T[]

arantes555 commented 4 months ago

@dremchee I believe Nedb.Cursor<T> extends Promise<Document<T>>, so it should already be the case once awaited, or am I wrong ?

dremchee commented 4 months ago

@dremchee I believe Nedb.Cursor<T> extends Promise<Document<T>>, so it should already be the case once awaited, or am I wrong ?

I mean the findAsync method, which should return an array For example sandbox https://codesandbox.io/p/sandbox/nedb-generic-type-pr8lvv?file=%2Fsrc%2Findex.ts%3A13%2C1

image image

RobMayer commented 3 months ago

I just encountered this. @dremchee is right.

// CURRENT BEHAVIOUR
const cursor = db.findAsync({ id: { $in: someArray}}(; // Cursor<T[]>
const result = await cursor.execAsync;() // Document<T[]>
result[0]._id // Should be a valid property but isn't showing up
result._id // Shouldn't be a valid property but is showing up

// EXPECTED BEHAVIOUR
const cursor = db.findAsync({ id: { $in: someArray}}(; // Cursor<T[]>
const result = await cursor.execAsync;() // Document<T>[]

result[0]._id // each row has an _id, does it now?