microsoft / microsoft/TypeScript

Type of reverse enum lookup is string | undefined with noUncheckedIndexedAccess enabled

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

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

In Discussion Suggestion
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
132

説明

Bug Report

🔎 Search Terms
  • enum
  • noUncheckedIndexedAccess
  • undefined
🕗 Version & Regression Information

This is a new feature in Typescript 4.1.

⏯ Playground Link

Playground link with relevant code

💻 Code
enum Foo {
  A, 
  B,
  C,
}

let x: string = Foo[Foo.A];
🙁 Actual behavior

With noUncheckedIndexedAccess it gives an error because the type of Foo[Foo.A] is determined to be string | undefined.

🙂 Expected behavior

I can't see any reason why the type shouldn't be string even with noUncheckedIndexedAccess enabled.

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

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

はじめの一歩

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

調査の方向性

リンクされた TypeScript Playground から始め、noUncheckedIndexedAccess を有効にして、enum の逆引き Foo[Foo.A] を調べます。この式の型チェックの動作を追跡します。string | undefined と報告されるのではなく、string として受け入れられれば完了です。

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

評価

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

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

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