nodejs-driver icon indicating copy to clipboard operation
nodejs-driver copied to clipboard

Fix "for...of" loop on `Result<T>` objects

Open ramikg opened this issue 1 year ago • 1 comments

Trying to iterate over a Result<T> object (e.g. one returned by calling find) using a "for...of" loop results in the following TypeScript error:

TS2488: Type Result<T> must have a [Symbol.iterator]() method that returns an iterator.

But, Result<T> explicitly implements [Symbol.iterator], so ignoring this type error fixes the "for...of" iteration.

This PR changes Result<T> from being an Iterator to being an IterableIterator (which means that it implements [Symbol.iterator]() in addition to being an Iterator).

ramikg avatar May 30 '24 11:05 ramikg

This PR originally added the method [Symbol.iterator] to the type definition of Result<T>.

The correct solution is to treat Result<T> as an IterableIterator.

ramikg avatar Sep 03 '24 10:09 ramikg

These fixes will be handled as part of the conversion to TypeScript. Thank you for this PR and bringing this to our attention!

SiyaoIsHiding avatar Jul 23 '25 19:07 SiyaoIsHiding