Skip to content

Enum allows numeric keys with leading 0s Β #58435

Closed as not planned
Closed as not planned
@laurenz-rausche

Description

@laurenz-rausche

πŸ”Ž Search Terms

"enum leading 0", "enum numeric"

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about "enums"

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.5.0-dev.20240504#code/KYOwrgtgBAKsDOAXAouCBvAUFKAiA+gAy5QC8eAJgPYJQDuVATgNZQCG8UAlolPABZUwAGwq5seYmTxRqtEFV4MW7Tjz6CRFKAsS4ANBNyEp5XMuacARmF4ChonYoNHCARhJn6TS1Bt3NR10XAF9MTDgkVEgAOiIIhBQ0GMIEqOSTNKTY9yA

πŸ’» Code

enum TestEnum{
  "_0" = "does work as it should"
  "0" = " does not work as it should not",
  "00" = "works but should not",
  "01" = " works but should not",
}

TestEnum._0
TestEnum.0
TestEnum.00
TestEnum.01

πŸ™ Actual behavior

An enum can be set with a numeric key when a leading 0 is added.

πŸ™‚ Expected behavior

The enum keys "00", "01", ... should not be allowed to be set, as they are unvalid to write as TestEnum.00, TestEnum.01, ...

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions