microsoft / microsoft/TypeScript
A tuple containing a spread not at the trailing edge has its minimum length calculated incorrectly
オープン
まだ誰も着手していません。
Bug
Domain: check: Type Inference
Help Wanted
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
Bug Report
🔎 Search Terms
- tuple
- spread
🕗 Version & Regression Information
It happens in v4.9.5, no idea about other versions.
⏯ Playground Link
💻 Code
type FN1 <T> = (...args: string[]) => T;
type FN2 <T> = ( ...args: [consumed: string, ...groups: string[], input: string, index: string] ) => T;
const fn1: FN1<number> = ( a, b ) => 0;
const fn2: FN2<number> = ( a, b ) => 0;
🙁 Actual behavior
TS complains about my fn2, with the following error:
Type '(a: string, b: string) => number' is not assignable to type 'FN2<number>'.
Types of parameters 'b' and 'groups' are incompatible.
Type '[...groups: string[], input: string, index: string]' is not assignable to type '[b: string]'.
Source has 2 element(s) but target allows only 1.(2322)
If I'm interpreting it correctly it is saying like "hey you defined two arguments, but maybe this tuple only has one item in it.
🙂 Expected behavior
If I'm interpreting the error correctly then the error is wrong because there's no scenario where that tuple has just one item in it, minimum it will always have 3.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされた TypeScript Playground で、issue にあるタプル型と関数型を使って報告内容を再現します。末尾以外の位置にある spread に対する、コンパイラのタプル最小長計算を追跡します。実際に短いタプルに対する既存の診断動作を正しく維持したまま、例でソースタプルが 1 要素しか持たない可能性があると報告されなくなれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 48/100