microsoft / microsoft/TypeScript
Continuing #17110 - Given generic `W extends { x: A }` should be able to use `keyof W['x']` to index w.x
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
TypeScript Version: typescript@3.7.0-dev.20190831
Search Terms: tagged disjoint union generic
This issue stems from a question I asked on StackOverflow that @jcalz generously researched for me. I adapted his example to be a closer parallel to the example given in #17110.
Code
interface A { a: string; }
interface W {
x: A
}
function foo<W1 extends W>(w: W1, k: keyof W1['x']) {
w.x[k]; // Type 'keyof W1["x"]' cannot be used to index type 'A'.
const x: W1['x'] = w.x; // Okay
x[k] // Okay
}
Expected behavior:
Same as #17110. However, unlike #17110, W['x'] is only A instead of A | B | undefined. The explanation given as to why #17110 was not a bug was:
The constraint of
keyof W1["x"]iskeyof (A | B), which simplifies tokeyof A & keyof B, which isnever(because there are no common properties).
However, here keyof W1['x'] is keyof A which is not never.
Actual behavior:
Same as #17110.
Related Issues: #17110
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、リンクされた Playground を使用し、期待される動作と実際の動作を比較して、typescript@3.7.0-dev.20190831 または TypeScript@next で汎用的なインデックス付けの例を再現します。既存の理由付けについては関連する issue #17110 を読んでください。報告されたアクセスが、関連する union のケースをリグレッションさせることなく受け入れられれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100