bajankristof / nedb-promises

A dead-simple promise wrapper for nedb.
MIT License
298 stars 45 forks source link

Return type of find() should be Cursor<T> #44

Closed paullessing closed 3 years ago

paullessing commented 3 years ago

Hi, I hope you don't mind be opening a PR for this issue. The return value of find() was previously Nedb.Cursor<(T & Document)[]>, which meant that the return value of Cursor.exec() ended up with a double-wrapped array.

Changing the interface of Cursor to always refer to the single entity, but extending a Promise of the array, fixes the issue (tested locally).

An alternative would have been to change the interface to Cursor<T extends any[]> implements Promise<T>, and update the return type of exec(): Promise<T>, but I felt that this option was simpler.

Let me know if you have any questions or feedback!

Fixes #43

bajankristof commented 3 years ago

I don't mind at all, thanks for the contribution!

bajankristof commented 3 years ago

I published the change to npm with 4.1.3