microsoft / microsoft/TypeScript
Enum declarations should consistently disallow computed keys
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Bug Report
🔎 Search Terms
Computed property names are not allowed in enumsenum declaration computed
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about enums
⏯ Playground Link
Playground link with relevant code
💻 Code
let y = "y";
type z = "z";
enum Foo {
['x'],
[{}],
[y],
[z]
}
🙁 Actual behavior
TS reports Computed property names are not allowed in enums. for [{}], [y] and [z], while it allows ['x'] (in contraddiction with the error message).
🙂 Expected behavior
All of them should be an error, for the reason reported by the error.
📚 Context
This came up at https://github.com/babel/babel/issues/12683: we can implement the current TS behavior in Babel, but I'd first like to check if TS is expected to report an error for ['x'].
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
Reproduce the behavior from the linked TypeScript Playground using the enum sample with ['x'], [{}], [y], and [z]. Trace the enum computed-property diagnostic from that example; done means all four declarations consistently produce the reported error, with coverage for the demonstrated cases.
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