You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
enumTestEnum{"_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._0TestEnum.0TestEnum.00TestEnum.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
The text was updated successfully, but these errors were encountered:
It's not about whether or not you can write TestEnum.Foo (e.g. "Foo Bar" = "works" is also legal) but whether the name of a member could potentially clash with a reverse mapping, so keys that overlap with the canonical string representation of a number are intentionally not allowed.
It's for the reason @fatcerberus said; while those can be parsed as numbers, they are not how those numbers would be represented when converted to strings, so they cannot conflict with reverse mappings. If there were no reverse mappings, all numeric keys would be allowed.
π Search Terms
"enum leading 0", "enum numeric"
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.5.0-dev.20240504#code/KYOwrgtgBAKsDOAXAouCBvAUFKAiA+gAy5QC8eAJgPYJQDuVATgNZQCG8UAlolPABZUwAGwq5seYmTxRqtEFV4MW7Tjz6CRFKAsS4ANBNyEp5XMuacARmF4ChonYoNHCARhJn6TS1Bt3NR10XAF9MTDgkVEgAOiIIhBQ0GMIEqOSTNKTY9yA
π» Code
π 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
The text was updated successfully, but these errors were encountered: