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
Erroneous control flow type narrowing in loops #15835
I just noticed what I believe is the same bug, but without the loop:
enumMyEnum{Foo,Bar}classMyClass{privatestate: MyEnum;// Set state to Barprivatemodify(){this.state=MyEnum.Bar;}publicfn(){this.state=MyEnum.Foothis.modify();if(this.state===MyEnum.Bar){// Do stuff here...}}}
This produces the following error
tmp.ts(19,13): error TS2365: Operator '===' cannot be applied to types 'MyEnum.Foo' and 'MyEnum.Bar'.
Just tested this with tsc version 2.7.2
Seems that typescript doesn't think that variables of enum type can ever change?
Activity
dead-claudia commentedon May 14, 2017
Note that neither of these variants reproduce the bug:
My current workaround is casting the
escapein the condition, like in this:Also, note that in my code, I have about 8-10 cases, for a
while/switch-based finite state machine loop.JShabtai commentedon Mar 15, 2018
I just noticed what I believe is the same bug, but without the loop:
This produces the following error
Just tested this with
tscversion 2.7.2Seems that typescript doesn't think that variables of enum type can ever change?
dead-claudia commentedon Mar 16, 2018
Josh (@JShabtai) Yours is subtly different:
RyanCavanaugh commentedon Mar 5, 2024
Works now. Other comment is a dupe of 9998