microsoft / microsoft/TypeScript

Two consecutive variadic elements in the middle part of tuple type can't be recognized

未关闭
#62,561 3 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

@ahejlsberg 已经在做这个了。

开始于 2025年10月8日。

Needs Investigation
主要语言
Go
星标
111k
派生
14.3k
平均合并
2 天 4 小时
30 天内合并 PR
132

描述

🔎 Search Terms

tuple, variadic element

🕗 Version & Regression Information

Since 4.0.5

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/GYVwdgxgLglg9mABMAPAFUQUwB5U2AEwGdFwBrMOAdzAG0BdAGkQDUtd9jSwLq76AfAApsALloAjOHAA2mAIZhmAOlUsVqtE0Srl8gE4BzIqJYBKRAG8AUIjt39mKCH1JsAbmsBfRNesQEIihEeUQAXmQhWih9EExmACZmACIJZOYYuO0ARhT5ZMQzd0QAehKAUX19OH1mHAAHTGhMAkQEkKMQAFt8KCJmCRBgwzhggGYgA

💻 Code
function f<U extends unknown[], V extends unknown[]>(x:[boolean, ...V, ...U], ...args:V) {
     return x;
} 

const a = f([true, 2, "b", true], 1, "a" ); //Error, expected 2 arguments, but got 3
🙁 Actual behavior

Compiler sees error

🙂 Expected behavior

No error, because as https://github.com/microsoft/TypeScript/pull/39094 states

If the middle part of T is exactly two variadic elements ...A and ...B, and an implied arity exists for A, infer from a tuple consisting of the initial middle part of S to A and from a tuple consisting of the remaining middle part of S to B, where the length of the initial middle part corresponds to the implied arity for A.

As I understand the middle part of S is 2, "b", true and in the middle part of T we have ...V, ...U then 2, "b" is ...V and true is ...U.

Additional information about the issue

https://stackoverflow.com/posts/79784883/edit

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。