Skip to content

Port TypeScript#63070: Be more lenient about iteration when lib=es5 / noLib#2753

Merged
jakebailey merged 2 commits intomainfrom
copilot/port-es5-iteration-changes
Feb 11, 2026
Merged

Port TypeScript#63070: Be more lenient about iteration when lib=es5 / noLib#2753
jakebailey merged 2 commits intomainfrom
copilot/port-es5-iteration-changes

Conversation

Copy link
Contributor

Copilot AI commented Feb 11, 2026

When lib=es5 or noLib but target is ES2015+, the checker would error on for..of loops claiming [Symbol.iterator]() is missing — which is impossible since no lib defines iterable types. This ports microsoft/TypeScript#63070.

The fix checks whether the global Iterable type actually exists before enabling uplevel iteration. When it doesn't, we fall back to ES5-ish behavior (arrays/strings are iterable, other types are not), consistent with how we already handle missing Promise for async/await.

iterableExists := c.getGlobalIterableType() != c.emptyGenericType
uplevelIteration := c.languageVersion >= core.ScriptTargetES2015 && iterableExists

Many existing .diff baseline files are deleted as previously-spurious errors are eliminated.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…s5 / noLib

When lib=es5 or noLib but target is ES2015+, we previously issued errors on
iterations complaining that [Symbol.iterator]() is missing, which was impossible
because there's no lib defining iterable types. This change adds a check for
whether the global Iterable type exists before enabling uplevel iteration,
falling back to ES5-ish behavior (allowing iteration on arrays/strings) when
the iterator types are missing.

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot AI changed the title [WIP] Port changes for lenient iteration handling in ES5 Port TypeScript#63070: Be more lenient about iteration when lib=es5 / noLib Feb 11, 2026
Copilot AI requested a review from jakebailey February 11, 2026 00:45
@jakebailey jakebailey marked this pull request as ready for review February 11, 2026 00:59
Copilot AI review requested due to automatic review settings February 11, 2026 00:59
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Ports TypeScript#63070 to the Go checker, making for..of (and related iteration features) more lenient when lib=es5/noLib but target is ES2015+, by only enabling ES2015 “uplevel iteration” semantics when the global Iterable type is actually present.

Changes:

  • Gate ES2015+ iterable-based iteration checking on the existence of the global Iterable type (getGlobalIterableType() != emptyGenericType).
  • Update baseline outputs to reflect the new behavior (removing previously-spurious TS2488 iterator errors and restoring ES5-ish array/string iteration behavior when libs are missing).
  • Delete/adjust many .diff baselines as error output converges with the intended behavior.

Reviewed changes

Copilot reviewed 93 out of 93 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/checker/checker.go Only enables ES2015 uplevel iteration when global Iterable exists; otherwise falls back to array/string iteration behavior.
testdata/baselines/reference/submodule/conformance/useObjectValuesAndEntries1(target=es2015).types.diff Baseline diff updated due to corrected iteration typing/error behavior.
testdata/baselines/reference/submodule/conformance/useObjectValuesAndEntries1(target=es2015).types Baseline types updated (e.g., for..of element types no longer degrade to any).
testdata/baselines/reference/submodule/conformance/useObjectValuesAndEntries1(target=es2015).errors.txt.diff Removes now-fixed spurious iterator errors from diff baseline.
testdata/baselines/reference/submodule/conformance/useObjectValuesAndEntries1(target=es2015).errors.txt Removes now-fixed spurious iterator errors from reference baseline.
testdata/baselines/reference/submodule/conformance/types.forAwait.es2018.3.errors.txt.diff Baseline diff updated to reflect fallback behavior when async iterable globals are missing.
testdata/baselines/reference/submodule/conformance/types.forAwait.es2018.3.errors.txt Updates expected diagnostics (e.g., array/string-based errors instead of [Symbol.asyncIterator] errors under missing libs).
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPatternDefaultValues3(target=es2015).types.diff Diff baseline updated due to improved/restored destructuring iteration typing.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPatternDefaultValues3(target=es2015).types Reference types baseline updated (rest/spread element types no longer become any).
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPatternDefaultValues3(target=es2015).errors.txt Removes spurious iterator errors from reference baseline.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPatternDefaultValues2(target=es2015).errors.txt.diff Removes spurious iterator errors from diff baseline.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPatternDefaultValues2(target=es2015).errors.txt Removes spurious iterator errors from reference baseline.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPatternDefaultValues(target=es2015).errors.txt.diff Removes spurious iterator errors from diff baseline.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPatternDefaultValues(target=es2015).errors.txt Removes spurious iterator errors from reference baseline.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern3(target=es2015).types.diff Diff baseline updated due to corrected iteration/destructuring typing.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern3(target=es2015).types Reference types baseline updated to restored specific element/rest types.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern3(target=es2015).errors.txt.diff Removes spurious iterator errors from diff baseline.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern3(target=es2015).errors.txt Removes spurious iterator errors from reference baseline.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern2(target=es2015).errors.txt.diff Removes spurious iterator errors from diff baseline.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern2(target=es2015).errors.txt Removes spurious iterator errors from reference baseline.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern(target=es2015).errors.txt.diff Removes spurious iterator errors from diff baseline.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern(target=es2015).errors.txt Removes spurious iterator errors from reference baseline.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringParametertArrayBindingPatternDefaultValues2(target=es2015).errors.txt.diff Removes spurious iterator errors from diff baseline.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringParametertArrayBindingPatternDefaultValues2(target=es2015).errors.txt Removes spurious iterator errors from reference baseline.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringParametertArrayBindingPatternDefaultValues(target=es2015).errors.txt.diff Removes spurious iterator errors from diff baseline.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringParametertArrayBindingPatternDefaultValues(target=es2015).errors.txt Removes spurious iterator errors from reference baseline.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringParametertArrayBindingPattern2(target=es2015).errors.txt.diff Removes spurious iterator errors from diff baseline.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringParametertArrayBindingPattern2(target=es2015).errors.txt Removes spurious iterator errors from reference baseline.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringParametertArrayBindingPattern(target=es2015).errors.txt.diff Removes spurious iterator errors from diff baseline.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringParametertArrayBindingPattern(target=es2015).errors.txt Removes spurious iterator errors from reference baseline.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringForOfObjectBindingPatternDefaultValues(target=es2015).types.diff Diff baseline updated due to corrected for..of destructuring typing.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringForOfObjectBindingPatternDefaultValues(target=es2015).types Reference types baseline updated (restored specific types instead of any).
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringForOfObjectBindingPatternDefaultValues(target=es2015).symbols.diff Diff baseline updated to reflect corrected symbol attribution under restored typing.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringForOfObjectBindingPatternDefaultValues(target=es2015).errors.txt.diff Removes spurious iterator errors from diff baseline.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringForOfObjectBindingPatternDefaultValues(target=es2015).errors.txt Removes spurious iterator errors from reference baseline.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringForOfObjectBindingPattern(target=es2015).types.diff Diff baseline updated due to corrected for..of destructuring typing.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringForOfObjectBindingPattern(target=es2015).types Reference types baseline updated (restored specific types instead of any).
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringForOfObjectBindingPattern(target=es2015).symbols.diff Diff baseline updated to reflect corrected symbol attribution under restored typing.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringForOfObjectBindingPattern(target=es2015).symbols Reference symbols baseline updated to match restored symbol resolution output.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringForOfObjectBindingPattern(target=es2015).errors.txt.diff Removes spurious iterator errors from diff baseline.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringForOfObjectBindingPattern(target=es2015).errors.txt Removes spurious iterator errors from reference baseline.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringForOfArrayBindingPatternDefaultValues2(target=es2015).types.diff Diff baseline updated due to corrected for..of destructuring/rest typing.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringForOfArrayBindingPatternDefaultValues2(target=es2015).types Reference types baseline updated (restored specific rest element types).
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringForOfArrayBindingPatternDefaultValues(target=es2015).errors.txt.diff Removes spurious iterator errors from diff baseline.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringForOfArrayBindingPatternDefaultValues(target=es2015).errors.txt Removes spurious iterator errors from reference baseline.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringForOfArrayBindingPattern2(target=es2015).types.diff Diff baseline updated due to corrected for..of destructuring/rest typing.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringForOfArrayBindingPattern2(target=es2015).types Reference types baseline updated (restored specific rest element types).
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringForOfArrayBindingPattern2(target=es2015).errors.txt Removes spurious iterator errors from reference baseline.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringForOfArrayBindingPattern(target=es2015).errors.txt Removes spurious iterator errors from reference baseline.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringForArrayBindingPatternDefaultValues2(target=es2015).types.diff Diff baseline updated due to corrected destructuring/rest typing in for statements.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringForArrayBindingPatternDefaultValues2(target=es2015).types Reference types baseline updated (restored specific rest element types).
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringForArrayBindingPattern2(target=es2015).types.diff Diff baseline updated due to corrected destructuring/rest typing in for statements.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringForArrayBindingPattern2(target=es2015).types Reference types baseline updated (restored specific rest element types).
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringForArrayBindingPattern(target=es2015).types.diff Diff baseline updated due to corrected destructuring/rest typing in for statements.
testdata/baselines/reference/submodule/compiler/sourceMapValidationDestructuringForArrayBindingPattern(target=es2015).types Reference types baseline updated (avoids any[] where specific union types are expected).
testdata/baselines/reference/submodule/compiler/arrayIterationLibES5TargetDifferent(nolib=true,target=esnext).types.diff Diff baseline updated due to new lenient iteration behavior under noLib.
testdata/baselines/reference/submodule/compiler/arrayIterationLibES5TargetDifferent(nolib=true,target=esnext).types Reference types baseline updated (string iteration yields string, not any).
testdata/baselines/reference/submodule/compiler/arrayIterationLibES5TargetDifferent(nolib=true,target=esnext).errors.txt.diff Removes spurious iterator errors under noLib from diff baseline.
testdata/baselines/reference/submodule/compiler/arrayIterationLibES5TargetDifferent(nolib=true,target=esnext).errors.txt Removes spurious iterator errors under noLib from reference baseline.
testdata/baselines/reference/submodule/compiler/arrayIterationLibES5TargetDifferent(nolib=true,target=es2015).types.diff Diff baseline updated due to new lenient iteration behavior under noLib.
testdata/baselines/reference/submodule/compiler/arrayIterationLibES5TargetDifferent(nolib=true,target=es2015).types Reference types baseline updated (string iteration yields string, not any).
testdata/baselines/reference/submodule/compiler/arrayIterationLibES5TargetDifferent(nolib=true,target=es2015).errors.txt.diff Removes spurious iterator errors under noLib from diff baseline.
testdata/baselines/reference/submodule/compiler/arrayIterationLibES5TargetDifferent(nolib=true,target=es2015).errors.txt Removes spurious iterator errors under noLib from reference baseline.
testdata/baselines/reference/submodule/compiler/arrayIterationLibES5TargetDifferent(nolib=false,target=esnext).types.diff Diff baseline updated due to corrected iteration checking semantics.
testdata/baselines/reference/submodule/compiler/arrayIterationLibES5TargetDifferent(nolib=false,target=esnext).types Reference types baseline updated (restores correct element types for iterable cases).
testdata/baselines/reference/submodule/compiler/arrayIterationLibES5TargetDifferent(nolib=false,target=esnext).errors.txt.diff Diff baseline updated (iterator-based TS2488 errors replaced by ES5-ish TS2495 where appropriate).
testdata/baselines/reference/submodule/compiler/arrayIterationLibES5TargetDifferent(nolib=false,target=esnext).errors.txt Reference errors baseline updated to the expected diagnostics under the new gating.
testdata/baselines/reference/submodule/compiler/arrayIterationLibES5TargetDifferent(nolib=false,target=es2015).types.diff Diff baseline updated due to corrected iteration checking semantics.
testdata/baselines/reference/submodule/compiler/arrayIterationLibES5TargetDifferent(nolib=false,target=es2015).types Reference types baseline updated (restores correct element types for iterable cases).
testdata/baselines/reference/submodule/compiler/arrayIterationLibES5TargetDifferent(nolib=false,target=es2015).errors.txt.diff Diff baseline updated (iterator-based TS2488 errors replaced by ES5-ish TS2495 where appropriate).
testdata/baselines/reference/submodule/compiler/arrayIterationLibES5TargetDifferent(nolib=false,target=es2015).errors.txt Reference errors baseline updated to the expected diagnostics under the new gating.

@jakebailey jakebailey enabled auto-merge February 11, 2026 01:33
@DanielRosenwasser
Copy link
Member

@jakebailey jakebailey added this pull request to the merge queue Feb 11, 2026
Merged via the queue into main with commit 1dc4b6d Feb 11, 2026
26 checks passed
@jakebailey jakebailey deleted the copilot/port-es5-iteration-changes branch February 11, 2026 19:31
Copilot AI added a commit that referenced this pull request Feb 25, 2026
… noLib (#2753)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants