microsoft / microsoft/TypeScript
Parameter type narrowing should consider function overload signatures
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
TypeScript Version: 2.2.1
Code
interface A { x: number; }
interface B { y: number; }
function foo(b: B): void;
function foo(a: A, b: B): void;
function foo(a: A|B, b?: B): void {
if(b !== void 0) {
console.log(a.y); // Error: Property 'y' does not exist on type 'A | B'
}
}
The third (unified) function signature is hidden from the call site, and therefore any arguments should be able to be narrowed based on inspection of the provided arguments. In the case above, the second argument is only defined if the first argument is of type A, and so I would expect narrowing of the argument type to occur accordingly. One could make the argument that in the compiled output, it's possible for JavaScript to still pass subsequent arguments, but then why narrow types at all, seeing as JavaScript can always violate every type constraint that TypeScript makes inferences from?
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
issue 内の TypeScript 2.2.1 の再現例から始め、パラメーターの絞り込み中にオーバーロードシグネチャーが統合された実装シグネチャーとどのように関係するかを調べます。a.y に対する現在の診断を確認し、その後、望ましい動作が記載されたオーバーロードと整合するかどうかを判断します。完了条件は、関連しない型チェックを弱めることなく、例で引数が期待どおりに絞り込まれることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100