microsoft / microsoft/TypeScript

`never` as keyof tuples/arrays behaves the same as `number`

オープン
#55,841 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

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

https://www.typescriptlang.org/play?ts=5.3.0-dev.20230923#code/C4TwDgpgBAglC8UDeBfA2gOwgNwgJwF0oB6YqQUHIotc8AoUSKAIQWSgEMAuKAZ2DwCWGAOZR01fEVIUqOfPXDQAwqzQFMcwiTKUJdBtAAiqvoJHq9UsoBlyXvyHCFjAKKtTDtRppWot9yKdoADFWAAp-UQAfKgBXAFsAI3wASk9LKG1fOzMo2MT8IA

💻 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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、リンク先の TypeScript Playground で動作を再現し、never を使ったオブジェクト、タプル、配列の例を比較します。タプルおよび配列のキーに対するコンパイラーのインデックスアクセス処理を追跡します。これらの例がオブジェクトのインデックスアクセスと一貫して never と評価され、適切なリグレッションテストのカバレッジがあることを完了条件とします。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
compilers
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。