Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ramikg
Copy link
Contributor

@ramikg ramikg commented May 30, 2024

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 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
Copy link
Contributor Author

ramikg commented Sep 3, 2024

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 ramikg force-pushed the bugfix/result-instance-for-loop branch from 339b6b4 to 0963ff5 Compare December 25, 2024 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant