microsoft / microsoft/TypeScript

Error when spreading a union of tuples in a call

オープン
#42,508 コメント 6 件 リアクション 0 件 担当者 1 名 GitHub で見る

@sandersn がすでに取り組んでいます。

2021年4月27日 から。

Bug Domain: check: Type Inference Rescheduled
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

Bug Report

🔎 Search Terms

destructure array typescript union

🕗 Version & Regression Information

I used the playground to test different versions and it looks like this has always occured.

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about "Type Systems behavior", "Type Guards", "Functions".
⏯ Playground Link

Playground link with relevant code

💻 Code
const t = [4,20] as const
const t2 = [4, 20, 30] as const
const t3 = [10, 10] as [number, number] | [number, number, number]

// Works
new Date().setHours(...t)
new Date().setHours(...t2)

// Error: Expected 1-4 arguments, but got 0 or more.
new Date().setHours(...t3)
🙁 Actual behavior

Error: Expected 1-4 arguments, but got 0 or more.

The array type passed as a length of 2 or 3 so the message "got 0 arguments" is wrong.

🙂 Expected behavior

I expect the compiler should be able to recognize that the array type can only have length 2 or 3 and would not throw an error.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。