Microsoft/TypeScript

ts2556 is too restrictive when generics are involved

Open

#57,322 创建于 2024年2月7日

在 GitHub 查看
 (2 评论) (3 反应) (0 负责人)TypeScript (6,726 fork)batch import
Domain: check: Type InferenceHelp WantedPossible Improvement

仓库指标

Star
 (48,455 star)
PR 合并指标
 (平均合并 6天 17小时) (30 天内合并 9 个 PR)

描述

🔎 Search Terms

"generic", "tuple", "spread", "rest", "ts2556", "a spread argument must either have a tuple type or be passed to a rest parameter"

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about spreading into argument lists

⏯ Playground Link

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

💻 Code

declare const f: () => void

declare const x: readonly []
f(...x) // works

const test = <T extends readonly []>(x: T) =>
  f(...x) // does not work

🙁 Actual behavior

Attempting to spread a generically-typed value whose constraint guarantees tuple-ness into a compatible argument list is forbidden.

🙂 Expected behavior

I should be allowed to do this.

Additional information about the issue

Possibly-related issues:

贡献者指南