Skip to content

noUncheckedIndexedAccess with enums could be type narrowed  #47508

@Stono

Description

@Stono

Bug Report

Hi, we're trying to tighten up some of our code by using noUncheckedIndexedAccess. I know there are caveats to this compiler option which we've found by searching, but this one feels more like a bug?

🔎 Search Terms

Searched a variety of issues, the most relevant being: #13778

🕗 Version & Regression Information

4.5.4

⏯ Playground Link

💻 Code

    enum Meat {
      Sausage,
      Bacon
    }
    const sausage = Meat.Sausage
    const value = Meat[sausage] // string | undefined

🙁 Actual behavior

value in the above example can't be undefined

🙂 Expected behavior

value to be typed as string, not string | undefined

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issueHelp WantedYou can do this

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions