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 TReturn/TNext to Iterable et al #58243
base: main
Are you sure you want to change the base?
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
@jakebailey, @weswigham: Am I missing something? The bot says there were interesting changes but it links to a clean pipeline result. |
@rbuckton Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
tsserverComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
startupComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
@rbuckton Here are the results of running the top 400 repos comparing Something interesting changed - please have a look. Details
|
@typescript-bot: pack this |
Hey @rbuckton, I've packed this into an installable tgz. You can install it for testing by referencing it in your
and then running There is also a playground for this build and an npm module you can use via |
Looks like you're introducing a change to the public API surface area. If this includes breaking changes, please document them on our wiki's API Breaking Changes page. Also, please make sure @DanielRosenwasser and @RyanCavanaugh are aware of the changes, just as a heads up. |
@typescript-bot run dt |
Hey @rbuckton, the results of running the DT tests are ready. There were interesting changes: Branch only errors:Package: regenerator-runtime
Package: async-iterable-stream
Package: consumable-stream/v1
Package: consumable-stream
Package: es-get-iterator
Package: consumable-stream/v2
|
@rbuckton Here are the results of running the user tests comparing Something interesting changed - please have a look. Details
|
@rbuckton Here are the results of running the user tests comparing There were infrastructure failures potentially unrelated to your change:
Otherwise... Everything looks good! |
The new flag is going to be interesting for DT where we don't actually have strict enabled (just null checks, implicit any, SFC). Maybe it's time that we just did that? |
DefinitelyTyped breaks will be addressed by DefinitelyTyped/DefinitelyTyped#69632 |
That fixes all of them even with the flag turned on? That's the bit I was worried about; not having coverage there because DT doesn't wholesale enable strict mode. |
@rbuckton Here are the results of running the top 400 repos comparing Something interesting changed - please have a look. Details
|
We avoided making this change in the past as it was very breaky, but at some point we need to address this discrepancy. Having incorrect types here is also causing problems with properly typing the Iterator Helpers proposal.
This also adds a new
BuiltinIteratorReturn
intrinsic type whose actual type is determined by the state of a newstrictBuiltinIteratorReturn
compiler option:"strictBuiltinIteratorReturn": false
-any
(emulates current behavior forIterableIterator
)"strictBuiltinIteratorReturn": true
-undefined
The
strictBuiltinIteratorReturn
is astrict
option flag, meaning that it is enabled automatically when you set"strict": true
in yourtsconfig.json
.The new
BuiltinIteratorReturn
type is passed as theTReturn
type argument for built-ins usingIterableIterator
orAsyncIterableIterator
to enable stricter checks against the result of callingnext()
on the iterator.Enabling
strictBuiltinIteratorReturn
results in a more accurate and type-safe return type for thenext()
methods of iterators produced by built-ins likeArray
,Set
,Map
, etc.:vs
Since this is a
strict
flag, there is a fair amount of existing code that will likely produce new compilation errors as a result of this change:This now fails as there is no correlation between
set.size
and the iterator produced bykeys()
, so the compiler is unaware that this constraint has been validated. If you are certain iterator will always yield at least one value, you can use a non-null assertion operator to strip off the| undefined
:A follow-on PR to TypeScript-DOM-lib-generator can be found here: microsoft/TypeScript-DOM-lib-generator#1713
DefinitelyTyped breaks will be addressed by DefinitelyTyped/DefinitelyTyped#69632
Fixes #33353
Fixes #52998
Fixes #43750
Supersedes #56517
Related #58222