Uh oh!
There was an error while loading. Please reload this page.
Add BuiltinIteratorReturn to IterableIterator and AsyncIterableIterator return types - #1713
Conversation
| interface ReadableStream<R = any> { | ||
| [Symbol.asyncIterator](options?: ReadableStreamIteratorOptions): AsyncIterableIterator<R>; | ||
| values(options?: ReadableStreamIteratorOptions): AsyncIterableIterator<R>; | ||
| [Symbol.asyncIterator](options?: ReadableStreamIteratorOptions): AsyncIterableIterator<R, BuiltinIteratorReturn>; |
There was a problem hiding this comment.
So BuiltinIteratorReturn can't be the default value to reduce verbosity?
There was a problem hiding this comment.
It can't be the default value because it's not the default behavior of any iterator, just the native ones provided by the host. User-defined iterables might not match that behavior, and we don't intend to break those cases unnecessarily.
Ron Buckton (rbuckton)
commented
Jul 19, 2024
Jake Bailey (@jakebailey) could you review? Also, what is the correct approach to handling the |
Ron Buckton (rbuckton)
commented
Jul 19, 2024
I've reverted the package.json/package-lock.json changes, but tests will fail until we at least have a nightly to point to |
Yeah, I would just wait for a nightly. If we really, really, really need it, we can run |
Jake Bailey (jakebailey)
left a comment
There was a problem hiding this comment.
Seems correct; feel free to use a PR build from pr-deploys if you want to be sure before tomorrow.
You might want to update TS dependency to nightly to fix the test. (Edit: #1713 (comment) already mentioned it) |
Jake Bailey (jakebailey)
commented
Jul 20, 2024
Updated it to help things along. |
Jake Bailey (jakebailey)
commented
Jul 20, 2024
Yay, green! |
Kenta Moriuchi (petamoriken)
commented
Jul 21, 2024
IMO, |
Ron Buckton (rbuckton)
commented
Jul 21, 2024
Honestly, I agree. I'll change it. |
Ron Buckton (rbuckton)
commented
Jul 22, 2024
The last commit aligns the generator with microsoft/TypeScript#59388 |
Ron Buckton (rbuckton)
commented
Jul 22, 2024
I'll update this to the nightly tomorrow before merging |
Ron Buckton (rbuckton)
commented
Jul 23, 2024
How will this change affect |
Jake Bailey (jakebailey)
commented
Jul 23, 2024
I'm not 100% certain; the readme for the Does |
Ron Buckton (rbuckton)
commented
Jul 23, 2024
It probably could, by tweaking deploy\createTypesPackages.js slightly to add a |
Maybe either bump the minor version or add |
Ron Buckton (rbuckton)
commented
Aug 6, 2024
Is a semver bump necessary if we add |
Jake Bailey (jakebailey)
commented
Aug 6, 2024
I don't think we need to bump semver if we are just adding a typesVersions; adding that is not a backwards incompatible change (otherwise we'd be totally dead on DT) |
Jake Bailey (jakebailey)
commented
Aug 6, 2024
Do the baselines also need the 5.5 variants? (I think so?) |
Oh, TIL that and sounds nice. I guess it's fine in that case. |
Ron Buckton (rbuckton)
commented
Aug 6, 2024
They did, yes. I just pushed up a commit that checks them. I think this should be ready for one more review pass. |
Jake Bailey (jakebailey)
commented
Aug 6, 2024
Actually, do Otherwise, things look correct to me. |
Ron Buckton (rbuckton)
commented
Aug 6, 2024
I'll test that locally and report back shortly. |
It would be nice to have some CI for that here, but I guess that can be done separately. |
Ron Buckton (rbuckton)
commented
Aug 6, 2024
|
Ron Buckton (rbuckton)
commented
Aug 6, 2024
The last commit should fix the |
The question would be that whether it works in 4.4 or otherwise it will still be a breaking change 🤔 |
Ron Buckton (rbuckton)
commented
Aug 6, 2024
I've tested it and it works fine with 4.4 as well. I mentioned 5.5 since that's where the split occurs as a result of the |
Jake Bailey (jakebailey)
commented
Aug 6, 2024
TS 4.4 is well out of support on DT (and that's what most tools use as their window), so I wouldn't worry about that too much. But good that it works! |
(Maybe this should also use DT window) |
| try { | ||
| outputFiles = fs.readdirSync(outputFolder); | ||
| } catch { | ||
| // do nothing |
There was a problem hiding this comment.
Are we actually expecting an error here? This looks like it could potentially silence a real failure 🤔
There was a problem hiding this comment.
the failures that matter are mismatched files. If either the input or output dir don't exist, then the file mismatch will be reported when we traverse whichever side did exist and find the file on the other side is missing.
This actually catches more failures as we previously only checked what was in baseline and ignored new things in generated. This now enumerates all distinct entries from both so we will report on excess baselines or excess outputs.
There was a problem hiding this comment.
Yeah, but we call stat before entering directory, so not sure this one matters.
There was a problem hiding this comment.
We call stat on both, but we still traverse the directory if the stat only succeeded on one side or the other, so the readddir can still potentially fail.
| /// Window Async Iterable APIs | ||
| ///////////////////////////// | ||
| interface FileSystemDirectoryHandleAsyncIterator<T> extends AsyncIteratorObject<T, BuiltinIteratorReturn, unknown> { |
There was a problem hiding this comment.
I don't understand this, is FooAsyncIterator basically same as BarAsyncIterator, because I don't see a difference between this and ReadableStreamAsyncIterator below?
There was a problem hiding this comment.
They have independent prototypes on the web, so you could theoretically augment ReadbleStreamAsyncIterator independently via its prototype:
varrs=newReadableStream();varproto=Object.getPrototypeOf(rs[Symbol.asyncIterator]());proto;// [object ReadableStream AsyncIterator]As with ArrayIterator, MapIterator, SetIterator, etc., we've opted to use interface names that more closely align with the underlying prototype.
There was a problem hiding this comment.
They have independent prototypes because the underlying iterator algorithms are different, but I wouldn't expect any independent members on them that would require separate declarations, at least not in the foreseeable future, because Web IDL simply doesn't have syntax for that and I don't see why IDL would want that.
Mattias Buelens (@MattiasBuelens) may have some opinion.
There was a problem hiding this comment.
Yes, but the general principle we've agreed on in microsoft/TypeScript#58243 and in design meeting is to try to give these things a relevant name. BuiltinIterator was too broad and confusing, and IteratorObject<T, BuiltinIteratorReturn, unknown> was too unwieldy and verbose. Since we must give these names, we've opted to give them names that reflect the actual runtime reality.
There was a problem hiding this comment.
Hmmmm. I guess it would be fine as we don't have too many iterable interfaces here, and also matching with TS principle makes sense. I still worry that this would encourage people do weird things that doesn't fit the spec intention though.
Ron Buckton (rbuckton)
commented
Aug 7, 2024
Kagami Sascha Rosylight (@saschanaz): any other concerns or feedback before this is merged? |
Besides what I already said, otherwise I'm good. |
This is a follow-on PR to microsoft/TypeScript#58243 to add
BuiltinIteratorReturnto allIterableIteratorandAsyncIterableIteratorreturn types.TODO:
"typescript"dependency in package.json to a shipping version that supportsBuiltinIteratorReturnand theTReturntype parameter forIterableIterator/AsyncIterableIteratorUpdate README.md to indicate the minimum TypeScript version