microsoft / microsoft/TypeScript
Type of reverse enum lookup is string | undefined with noUncheckedIndexedAccess enabled
Open
Nobody has claimed this yet.
In Discussion
Suggestion
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked TypeScript Playground, enabling noUncheckedIndexedAccess and examining the reverse enum lookup Foo[Foo.A]. Trace the type-checking behavior for this expression; done means it is accepted as a string rather than reported as string | undefined.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100