microsoft / microsoft/TypeScript
extends causing string literal can't be used as index
オープン
まだ誰も着手していません。
Domain: Indexed Access Types
Possible Improvement
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
Bug Report
🔎 Search Terms
cannot be used as an index type
🕗 Version & Regression Information
- This changed between versions 4.9.5 and 5.0.4
⏯ Playground Link
Playground link with relevant code
💻 Code
interface Dict {
foo: 1
bar: 1
}
type A = Dict['foo'] // works
type F = 'foo'
type B = Dict[F] // works
type FF = 'foo' extends ('foo' | 'bar') ? 'foo' : never // in theory, FF === F
type C = Dict[FF] // not working, Type '"foo"' cannot be used as an index type.(2538)
🙁 Actual behavior
type C throws error
🙂 Expected behavior
no error
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンク先の TypeScript Playground から始め、報告されたバージョン全体で Dict、F、FF、C の最小例を再現してください。文字列リテラルに解決される条件型に対するインデックスアクセスの型チェック経路を追跡し、その後、この例に基づく回帰テストを追加してください。type C = Dict[FF] でエラーが発生しなければ完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100