microsoft / microsoft/TypeScript
`never` as keyof tuples/arrays behaves the same as `number`
オープン
まだ誰も着手していません。
Domain: Indexed Access Types
Possible Improvement
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
🔎 Search Terms
tuple keyof never, tuple[never], array keyof never
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about this issue
Versions I tried:
- 5.2.2
- nightly (playground)
⏯ Playground Link
💻 Code
type A = {}[never] // ✅ never
type B = { a: string }[never] // ✅ never
type C = [][never] // ✅ never
type D = [string][never] // ❌ string
type E = string[][never] // ❌ string
type F = (string | number)[][never] // ❌ string | number
🙁 Actual behavior
After using a never key on tuples/arrays you get back the entirety of the tuple/array elements type.
🙂 Expected behavior
After using a never key on tuples/arrays you get back never, as when dealing with objects.
Additional information about the issue
Not sure if this has historical reasons to behave like it does, but couldn't find any specific info about it.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、リンク先の TypeScript Playground で動作を再現し、never を使ったオブジェクト、タプル、配列の例を比較します。タプルおよび配列のキーに対するコンパイラーのインデックスアクセス処理を追跡します。これらの例がオブジェクトのインデックスアクセスと一貫して never と評価され、適切なリグレッションテストのカバレッジがあることを完了条件とします。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100