-
Notifications
You must be signed in to change notification settings - Fork 12.8k
IteratorResult should be a discriminated union #28670
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
Comments
I think I just force cast to as any or sth. Edit: //We passed the end of the last page
return {
done : true,
value : undefined as any,
}; |
@AnyhowStep Yeah, that was my workaround too. But I think it shouldn't be, hence the request. |
duplicate of #11375? |
According to the spec and MDN the type IteratorResult<T> =
{ readonly done: true, readonly value?: T } |
{ readonly done: false, readonly value: T } or even: type IteratorResult<T> =
{ readonly done: true, readonly value?: any } |
{ readonly done: false, readonly value: T } |
@rbuckton think we've got enough infrastructure in place to be able to try this lib change yet? |
@hwanders If we were to follow the spec, type IteratorResult<T> =
{ readonly done: true, readonly value?: T } |
{ readonly done?: false, readonly value: T } |
For reference, @KSXGitHub is talking about this: https://tc39.github.io/ecma262/#sec-iteratorresult-interface (emphasis added):
And this (emphasis added):
|
There is, however, nothing that indicates |
@rbuckton Although the spec does not demand the properties to be either writable or read-only, not making them read-only makes it impossible to use a read-only object (e.g. frozen) as an |
This issue has been marked as a duplicate and has seen no activity in the last day. It has been closed automatic house-keeping purposes. |
Suggestion
Current definition of
IteratorResult
demandsvalue
to be provided regardless of whetherdone
istrue
orfalse
.Suggestion: Change
IteratorResult
to something like thisUse Cases
I am currently trying to build a custom async iterator that cannot be done with async generator, it is absurd that I had to provide some value when iteration is done.
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: