Skip to content

enum member key should reject computed stringΒ #61834

@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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy