-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Generator helper should include [Symbol.toStringTag] #35833
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
This is so bizarre to me - why on earth would code want to defensively check like this when generators are not the only way to produce iterators? |
Do note that it should also inherit from |
I'd be happy to open a PR for this issue, the fix seems clear. Contribution guidelines suggest I should wait for a "help wanted" label. Would folks be open to that contribution? |
@rbuckton thoughts? |
There is no %IteratorPrototype% down-level, and even if the iterator helpers proposal advances, I don't believe we would attempt to ship a polyfill for that behavior. Also, our helpers can often run in isolated contexts (i.e. inside of a single module), so there's no guaranteed way to create a shared %IteratorPrototype% I concur with @DanielRosenwasser, just having a Rather, I wonder at the reason why |
To clarify, the check in
This been mentioned a few times, is the following the type of check you would suggest? function isGenerator(x) {
return !!x && typeof x[Symbol.iterator] === 'function';
}
function* makeGen() { }
const gen = makeGen();
console.log(isGenerator(gen)); // true This check does seem to be satisfied by native, regenerator-runtime, and the TypeScript down-level implementation. I can propose that change to FYI: @aduth |
Yeah, I think that's probably a more appropriate check, though you'd want to name the function something like |
Rather than checking the `Symbol.toStringTag` property, check for `iterator` and `iterable` interfaces that are more widely supported by helper libs. Related issue: microsoft/TypeScript#35833
In WordPress/gutenberg#19666 we changed the check in
Thanks for the feedback everyone. With the change in |
TypeScript Version:
3.8.0-dev.20191223
and3.7.3
Search Terms:
Generator, toStringTag, transformer, helper, tslib
Code
The following code will error in when using
compilerOptions.target = es5
, but works correctly when compiled withtarget = es2015
or greater.Expected behavior:
The property should be set as expected via the helpers.
Generators should include the
Symbol.toStringTag
property"Generator"
according to spec.Some libraries check for a generator by inspecting this property. For example,
@wordpress/redux-routine
checks for this property and does not correctly handle generators produced by the helper.regenerator-runtime
is a widely used generator helper which does set this property.Actual behavior:
Symbol.toStringTag
is not included on the generator.Playground Link:
Broken with target=es5
Working with target=es2015
Related Issues:
#19006
The text was updated successfully, but these errors were encountered: