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
{{ message }}
Repository navigation
Negative constant enums return number when toString is called #54992
changed the title [-]Negative numbered constant enums return typeof number when toString is called[/-][+]Negative numbered constant enums return number when toString is called[/+]on Jul 12, 2023
If anyone's wondering how this happens, it's because the emit is -1 .toString() - property access has higher precedence than negation. So effectively what happens is this logs the result of typeof -(1..toString()) -- which is number.
Reacted by Dustin Brett, Martin Johns, Joe Calzaretta, Ryan Cavanaugh, uhyo, Zzzen and Darryl Noakes
changed the title [-]Negative numbered constant enums return number when toString is called[/-][+]Negative constant enums return number when toString is called[/+]on Jul 12, 2023
I don’t think people generally call methods on enum values, since they’re usually just meant to be used as sentinels. Probably even fewer people still use negative values.
Activity
[-]Negative numbered constant enums return typeof number when toString is called[/-][+]Negative numbered constant enums return number when toString is called[/+]fatcerberus commentedon Jul 12, 2023
If anyone's wondering how this happens, it's because the emit is
-1 .toString()- property access has higher precedence than negation. So effectively what happens is this logs the result oftypeof -(1..toString())-- which isnumber.[-]Negative numbered constant enums return number when toString is called[/-][+]Negative constant enums return number when toString is called[/+]RyanCavanaugh commentedon Jul 12, 2023
I'm honestly shocked this has been shipping since at least 3.3, possibly forever, without getting noticed 😰
fatcerberus commentedon Jul 12, 2023
I don’t think people generally call methods on enum values, since they’re usually just meant to be used as sentinels. Probably even fewer people still use negative values.