-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Enum can be assigned out-of-bounds values #30629
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
Comments
I believe this is by design as stated by @DanielRosenwasser in #26362 to allow for bitwise operations on flag enums:
|
That makes sense but then they should geek out and understand that you cannot produce |
@jrieken Challenge accepted 😄 : let value: Fonum = Fonum.a << Fonum.b << Fonum.a | Fonum.a << Fonum.b; // 12 I think it is difficult to tell if the resulting number is valid or not if we consider flag enums and the whole range of bitwise operations. |
haha - fair point. There should probably be |
TypeScript Version: 3.4.0-rc
https://www.typescriptlang.org/play/#src=const%20enum%20Fonum%20%20%7B%0D%0A%20%20%20%20a%20%3D%201%2C%0D%0A%20%20%20%20b%20%3D%202%0D%0A%7D%0D%0A%0D%0Alet%20value%3A%20Fonum%20%3D%2012%3B%20%2F%2F%20no%20error%3F%0D%0A%0D%0Alet%20value2%3A%201%20%7C%202%20%3D%2012%3B%20%2F%2F%20error
The text was updated successfully, but these errors were encountered: