microsoft / microsoft/TypeScript

Inconsistent error between different versions of the same function with required parameter following an optional one

オープン
#57,565 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Awaiting More Feedback Suggestion
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

🔎 Search Terms

error function optional required rest

🕗 Version & Regression Information
  • This is the behavior in every version I tried
⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.5.0-dev.20240227#code/GYVwdgxgLglg9mABAIwIYCcAUqBciwgC2yApugDQoD8eBxZlEtRpFiAdJxgOYDOevKOhhhuAbQC6ASkQBvAL4AoRWnSKA9OsQA9KolCRYCFBmzN6bZDXwsGiJjYuVO7Hv0SDhoyVLwA3OBgAE2VVTABGKQBuRE1EAFEADwAHEmgSIMRUKEQAGxJUQUQAZiz0biISMCheSmQQHO44HPD2TAAmAFZuqWUDaHgkNAAvM0dWOus6CY4ucvcxB2m7FzcBIRFxCWk5JRVUYY0tXX1wAeMRseXLKds2JbvnOb51ry3fRADg0IOI6NitElUulMtk8gUiqUeJVqrUUA1EE0Wm0uj1FEA

💻 Code
function bar(a: number, b?: number, c: number, ...args: string[]) {}

bar
// ^? function bar(a: number, b?: number, c: number, ...args: string[]): void

bar(1); // Expected at least 3 arguments, but got 1.(2555)

function baz(a: number, b?: number, ...args: [c: number, ...args: string[]]) {}

baz
// ^? function baz(a: number, b?: number, c: number, ...args: string[]): void

baz(1); // Expected at least 3 arguments, but got 1.(2555)
🙁 Actual behavior

We get an error within the bar declaration ("'c' is declared but its value is never read.(6133)") but we get none in baz. They are pretty much equivalent.

🙂 Expected behavior

I'd expect this error to be raised consistently here (or not raised consistently).

In addition to that, b comes with the question mark in both quick infos here. TypeScript understands that at least 3 arguments are required here. It means that effectively b is required in both cases and ? is somewhat misleading here. I think it would be good to normalize this. It already is normalized with tuples:

type A = [a: number, b?: number, ...[c: number, ...args: string[]]]
//   ^? type A = [a: number, b: number | undefined, c: number, ...args: string[]]
Additional information about the issue

No response

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

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

はじめの一歩

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

調査の方向性

提供された TypeScript Playground の例から始め、bar と baz の診断を、それぞれの quick-info シグネチャを含めて比較します。未使用パラメーターの診断とオプションパラメーターの正規化を一貫させるべきかどうかを決定し、選択した動作に対するコンパイラーのカバレッジを追加または更新できれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
compilers
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

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

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