Skip to content

lib: reject primitive strings from iterator flatMap mappers - #65372

Open
David Kaminski (dvkam) wants to merge 1 commit into
microsoft:mainfrom
dvkam:fix/iterator-flatmap-primitive-string
Open

David Kaminski (dvkam) wants to merge 1 commit into
microsoft:mainfrom
dvkam:fix/iterator-flatmap-primitive-string

Conversation

@dvkam

Copy link
Copy Markdown

Fixes #65370

Change

Require the Iterator.prototype.flatMap mapper to return an iterator or iterable object. Primitive strings satisfy Iterable<string> in TypeScript, but ECMAScript rejects them when the result is consumed.

Tests

Added a compiler case that rejects a primitive string and preserves arrays, boxed strings, and iterator objects. Updated the affected baselines. The compiler baseline suite passed in default and concurrent modes on the reviewed patch.

I used AI assistance to prepare this change and personally reviewed the code and the issue report.

Copilot AI balanced review requested due to automatic review settings November 7, 2026 00:21
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Nov 7, 2026
@typescript-automation typescript-automation Bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Nov 7, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the change requiring iterator flatMap mapper results to be objects.

No open issues 🎉

What changed in this PR

Fixes #65370 by aligning TypeScript’s Iterator.prototype.flatMap declaration with ECMAScript’s requirement that mapper results be objects, rejecting primitive strings.

Changes:

  • Intersects the mapper’s return type with object.
  • Adds regression coverage for rejected primitive strings and accepted arrays, iterator objects, and boxed strings.
  • Updates type, symbol, and diagnostic baselines.
File Description
tsc/​testdata/​tests/​cases/​compiler/​iteratorFlatMapRejectsPrimitiveString.ts Tests rejected and supported mapper results.
tsc/​testdata/​baselines/​reference/​compiler/​iteratorFlatMapRejectsPrimitiveString.types Records inferred types for the new test.
tsc/​testdata/​baselines/​reference/​compiler/​iteratorFlatMapRejectsPrimitiveString.symbols Records symbol bindings for the new test.
tsc/​testdata/​baselines/​reference/​compiler/​iteratorFlatMapRejectsPrimitiveString.errors.txt Captures the primitive-string rejection diagnostic.
tsc/​testdata/​baselines/​reference/​compiler/​builtinIterator.types Updates existing snapshots of the flatMap signature.
tsc/​testdata/​baselines/​reference/​compiler/​builtinIterator.errors.txt Updates existing diagnostics for the constrained return type.
tsc/​internal/​bundled/​libs/​lib.es2025.iterator.d.ts Requires flatMap mapper results to be objects.

Review effort: Balanced

@dvkam

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

Iterator.prototype.flatMap accepts primitive string results

2 participants