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
Numeric enums are not type safe
You can assign any number to numeric enums.
enum ZeroOrOne {
Zero = 0,
One = 1
}
const zeroOrOne: ZeroOrOne = 2; // no error!!
Version
As far I have work with enums I can not assing any literal value (Regarless the type...) so the error would be even this const zeroOrOne: ZeroOrOne = 1; as the literal value is not an enum value.
Perhaphs this is something you already know about, but I don't know and I think it is okey to report this here as an issue.
Thanks for reading... forgive me if I'm wrong in something.
Greetings.
Víctor.
The text was updated successfully, but these errors were encountered:
Thanks @RyanCavanaugh for the quick answer. I see there is tradeoff here. Dificult chooise.. or you can have bitwise operations enums and strict enums, and everybody happy.
HI there, how you doing guys? Hope fine.
I was studying a little bit the diff between using enums vs (union types + literal types) on this post at stackoverflow.
A given person states the following in his answer
Version
As far I have work with enums I can not assing any literal value (Regarless the type...) so the error would be even this
const zeroOrOne: ZeroOrOne = 1;
as the literal value is not an enum value.Perhaphs this is something you already know about, but I don't know and I think it is okey to report this here as an issue.
Thanks for reading... forgive me if I'm wrong in something.
Greetings.
Víctor.
The text was updated successfully, but these errors were encountered: