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 天内回复