microsoft / microsoft/TypeScript
Infering type of optional parameter of lambda function is broken when passed to generic function.
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
TypeScript Version: 3.7.0-beta, nightly and older ones
Search Terms:
optional parameter infer lambda generic
Code
declare function noop<T>(val: T): T;
const f = (a: string, b = 23) => b;
// reports "Parameter 'b' implicitly has an 'any' type."
// broken since v3.5.1, older versions work well
const foo = noop((a: string, b = 23) => b);
// (a: string, b?: number) => number
const bar = noop(f);
declare function noop2<T extends (...params: any[]) => any>(val: T): T;
// (a: string, b?: any) => any (BUG)
const foo2 = noop2((a = 23) => a); // broken on all versions
// (a: string, b?: number) => number
const bar2 = noop2(f);
Expected behavior:
foo* and bar* should all have the same type.
Actual behavior:
In the first case, the compiler complains that it can't infer the type of optional argument of lambda forwarded to noop, and in the second case it silently assigns any type to b instead of number
Playground Link:
Notes
The mentioned versions of typescript are not exact, I just used TypeScript playground and the set of available versions there.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、リンク先の TypeScript Playground の例、特にオプションのラムダパラメーターを指定した noop と noop2 の呼び出しを再現します。これらの式に対するコンパイラーのジェネリック推論と文脈的型付けを追跡します。foo、bar、foo2、bar2 が implicit any エラーなしで同等のパラメーター型と戻り値型を推論できれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100