microsoft / microsoft/TypeScript
The intersection of a tuple with an unrelated array is handled inconsistently
还没有人认领这个 Issue。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 1 天 19 小时
- 30 天内合并 PR
- 117
描述
Bug Report
🔎 Search Terms
tuple, intersection, array, unrelated, narrowing, index signature
🕗 Version & Regression Information
This is the behavior in every version I tried
⏯ Playground Link
Playground link with relevant code
💻 Code
/* unrelated array */
type ShouldBeNever = string[] & [1, 2, 3]
type OK = (ShouldBeNever)[number] // never
type NotOK = (ShouldBeNever)[1] // 2
type WeirdOverload = (ShouldBeNever)['pop'] // {
// (): string | undefined
// (): 3 | 1 | 2 | undefined
//}
const isString = ([1, 2, 3] as ShouldBeNever).pop() // string | undefined
/* related array but not a supertype */
type ShouldBeNarrowed = [number | string, number | boolean] & (string | boolean | symbol)[]
type FF = ShouldBeNarrowed[number] // string | boolean
type HH = ShouldBeNarrowed[0] // string | number
🙁 Actual behavior
The index signature is appropriately updated, but not the individual elements nor the methods operating on the resulting tuple. Additionally, methods get overloaded, so when calling pop for example, the first overload is selected and the return type is not the intersection of the original components return types as it should be.
🙂 Expected behavior
I would expect ShouldBeNever to be [never, never, never] and ShouldBeNarrowed to be [string, boolean]
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从链接的 TypeScript Playground 开始,复现 ShouldBeNever 和 ShouldBeNarrowed 的 indexed access 及数组方法结果。跟踪元组交集如何更新索引签名、元素类型和方法;完成的标准是示例能够产生预期的 never 和缩窄后的元组类型,且不会出现不一致的重载结果。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100