New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enum allows numeric keys with leading 0s #58435
Comments
Bracket notation is still valid: |
Yeah, but in that sense |
It's not about whether or not you can write |
This isn't a bug: all of the following are intentionally allowed: enum TestEnum {
"1e2",
"3.40",
".567",
"88888888888888888"
} 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. |
Oh okay! Thank you for the information, and sorry for the wrong assumption and the disturbance :D |
π 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: