Skip to content

Enum declarations should consistently disallow computed keysΒ #42468

Open
@nicolo-ribaudo

Description

@nicolo-ribaudo

Bug Report

πŸ”Ž Search Terms

  • Computed property names are not allowed in enums
  • enum 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 babel/babel#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'].

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: Error MessagesThe issue relates to error messaging

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions