Iterator.prototype.flatMap accepts primitive string results
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 84/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- typescript
研究方向
從 lib.es2025.iterator.d.ts 開始,比較 flatMap 回呼的回傳型別與 Iterator.concat 使用的物件限制。issue 提供了嚴格的 TypeScript 重現範例和預期的型別變更;執行提供的 tsc 命令,檢查原始字串會被拒絕,而陣列、迭代器物件和裝箱字串仍會被接受。
由索引模型根據 Issue 內容生成。
描述
Compilation target
ES5 (default).
Library
es2025
Missing / Incorrect Definition
lib.es2025.iterator.d.ts accepts a primitive string as the mapper's return value because a string satisfies Iterable<U>. ECMAScript rejects that value when the iterator is consumed.
TypeScript 7.1.0-dev.20261106.1 accepts the sample below. Node 26.13.0 throws TypeError: Iterator.prototype.flatMap called on non-object when toArray() consumes the iterator. TypeScript should reject the callback's return type.
Copy the code under Sample Code into repro.ts in an empty directory. Run the following commands there.
npx --yes [email protected] tsc --noEmit --strict --lib es2025 repro.ts
node repro.ts
Intersect the callback's existing return union with object. This matches the object constraint used by Iterator.concat and preserves arrays, iterator objects, and boxed strings.
- flatMap<U>(callback: (value: T, index: number) => Iterator<U, unknown, undefined> | Iterable<U, unknown, undefined>): IteratorObject<U, undefined, unknown>;
+ flatMap<U>(callback: (value: T, index: number) => (Iterator<U, unknown, undefined> | Iterable<U, unknown, undefined>) & object): IteratorObject<U, undefined, unknown>;
Sample Code
Iterator.from([1]).flatMap(() => "ab").toArray();
Documentation Link
- 主要語言
- Go
- 星號
- 112k
- 分支
- 15.4k
- 平均合併
- 3 天 2 小時
- 30 天內合併 PR
- 149
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
microsoft/TypeScript 的其他 Issue
-
ESNext.SharedMemory still declares the removed Atomics.pause parameter可能已有人在做 @JemmyIndex 今天認領。 未關閉
難度 1/5 1 小時以內 新手友好度 88/100
microsoft/TypeScript#65339 ·
維護者通常 1 天內回覆
-
Native API: formatDiagnosticsWithColorAndContext drops related information without a file location可能重新可做 關聯的 PR 已關閉且未合併。 未關閉
難度 2/5 1-3 小時 新手友好度 75/100
microsoft/TypeScript#65087 ·
維護者通常 1 天內回覆
-
TS7 LSP: documentHighlight returns nothing when the file path contains '@'可能重新可做 關聯的 PR 已關閉且未合併。 未關閉Bug
難度 2/5 1-3 小時 新手友好度 78/100
microsoft/TypeScript#64758 ·
維護者通常 1 天內回覆
-
Language server (tsc --lsp) exits with code 1 after `shutdown` and `exit`可能已有人在做 @rajnish-verma-22172 於 16 天前認領。 未關閉Bug
難度 2/5 1-3 小時 新手友好度 76/100
microsoft/TypeScript#64742 · 1 則留言 ·
維護者通常 1 天內回覆
-
Non-enum CLI options with multiple values separated by comma and space aren't whitespace trimmed可能已有人在做 @RyanCavanaugh 於 31 天前認領。 未關閉Bug
難度 2/5 1-3 小時 新手友好度 68/100
microsoft/TypeScript#64618 · 已指派 1 人 ·
維護者通常 1 天內回覆
查看 microsoft/TypeScript 的全部 Issue
相似的 Issue
-
bug tech debt testing
難度 2/5 1-3 小時 新手友好度 76/100
aws/amazon-vpc-cni-k8s#3976 ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 83/100
txn2/mcp-data-platform#2522 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 72/100
open-telemetry/opentelemetry-go-contrib#10234 ·
維護者通常 1 天內回覆
-
discovery/backoff: default FindPeers limit yields no fresh peers可能已有人在做 @zakazaka95 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 75/100
-
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆