microsoft / microsoft/TypeScript
Type Inference in for... in combined with typeof
オープン
まだ誰も着手していません。
Help Wanted
Suggestion
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
TypeScript Version: 2.1.4
The following code gives an error in TS 2.1:
It's not really nice code, but I think it should work never the less :)
for (var a in this) {
if (typeof this[a] === "function" && !ko.isObservable(this[a]))
this[a] = this[a].bind(this);
}
Expected behavior:
I would expect this[a] to be typed as this[keyof this] & Function:
for (var a in this) {
if (typeof this[a] === "function" && !ko.isObservable(this[a]))
this[a] =( <this[keyof this] & Function> this[a]).bind(this);
}
Actual behavior:
It gives an error, as of TS 2.1, it worked in TS 2.0 (because mapped types did not exist, this[a] was typed as any)
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
提供された for...in と typeof の例で TypeScript 2.1 のエラーを再現し、その後 TypeScript 2.0 での動作と比較します。for...in の narrowing パスを通じた this[a] の型推論を追跡します。明示的な cast なしで例の型チェックが通り、期待される関数の narrowing が維持されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100