-
Notifications
You must be signed in to change notification settings - Fork 424
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
Add BuiltinIteratorReturn to IterableIterator and AsyncIterableIterator return types #1713
Conversation
@@ -3,6 +3,6 @@ | |||
///////////////////////////// | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So BuiltinIteratorReturn can't be the default value to reduce verbosity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@jakebailey could you review? Also, what is the correct approach to handling the |
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
Updated it to help things along. |
Yay, green! |
IMO, |
Honestly, I agree. I'll change it. |
The last commit aligns the generator with microsoft/TypeScript#59388 |
I'll update this to the nightly tomorrow before merging |
How will this change affect |
I'm not 100% certain; the readme for the Does |
It probably could, by tweaking deploy\createTypesPackages.js slightly to add a |
Maybe either bump the minor version or add |
This LGTM but do we need to come up with some typesVersions something to make things not break for old TS versions? Or just remove the language about TS version support? |
Is a semver bump necessary if we add |
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) |
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. |
They did, yes. I just pushed up a commit that checks them. I think this should be ready for one more review pass. |
Actually, do Otherwise, things look correct to me. |
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. |
|
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 🤔 |
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 |
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we actually expecting an error here? This looks like it could potentially silence a real failure 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but we call stat before entering directory, so not sure this one matters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -2,14 +2,22 @@ | |||
/// Window Async Iterable APIs | |||
///////////////////////////// | |||
|
|||
interface FileSystemDirectoryHandleAsyncIterator<T> extends AsyncIteratorObject<T, BuiltinIteratorReturn, unknown> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They have independent prototypes on the web, so you could theoretically augment ReadbleStreamAsyncIterator
independently via its prototype:
var rs = new ReadableStream();
var proto = 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@MattiasBuelens may have some opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@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
BuiltinIteratorReturn
to allIterableIterator
andAsyncIterableIterator
return types.TODO:
"typescript"
dependency in package.json to a shipping version that supportsBuiltinIteratorReturn
and theTReturn
type parameter forIterableIterator
/AsyncIterableIterator
Update README.md to indicate the minimum TypeScript version