microsoft / microsoft/TypeScript
Inconsistent error between different versions of the same function with required parameter following an optional one
まだ誰も着手していません。
- 主要言語
- 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
💻 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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
提供された TypeScript Playground の例から始め、bar と baz の診断を、それぞれの quick-info シグネチャを含めて比較します。未使用パラメーターの診断とオプションパラメーターの正規化を一貫させるべきかどうかを決定し、選択した動作に対するコンパイラーのカバレッジを追加または更新できれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100