Skip to content

enum member key should reject computed stringΒ #61834

Closed as not planned
Closed as not planned
@fisker

Description

@fisker

πŸ”Ž Search Terms

enum, computed, member key, string

πŸ•— Version & Regression Information

This is the behavior in every version I tried.

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.9.0-dev.20250608#code/KYOwrgtgBAYg9nKBvAsAKClA2gcgII4C6UAvFAIzoC+6QA

πŸ’» Code

enum Foo {
  ['A'] = 1
}

πŸ™ Actual behavior

"use strict";
var Foo;
(function (Foo) {
    Foo[Foo['A'] = 1] = 'A';
})(Foo || (Foo = {}));

πŸ™‚ Expected behavior

When using

enum Foo {
  [A] = 1
}

it emits error

Computed property names are not allowed in enums.

Should we forbid computed strings as well?

Additional information about the issue

typescript-eslint/typescript-eslint#11232 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions