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
The behavior is motivated by bitwise operations. There are times when SomeFlag.Foo | SomeFlag.Bar is intended to produce another SomeFlag. Instead you end up with number, and you don't want to have to cast back to SomeFlag.
I think if we did TypeScript over again and still had enums, we'd have made a separate construct for bit flags.
Activity
dragomirtitian commentedon Mar 28, 2019
I believe this is by design as stated by Daniel Rosenwasser (@DanielRosenwasser) in #26362 to allow for bitwise operations on flag enums:
jrieken commentedon Mar 28, 2019
That makes sense but then they should geek out and understand that you cannot produce
12with1and/or2dragomirtitian commentedon Mar 28, 2019
Johannes Rieken (@jrieken) Challenge accepted 😄 :
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.
jrieken commentedon Mar 28, 2019
haha - fair point. There should probably be
strict enumthat doesn't allow these things...