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
Property with getter: This condition will always return 'false'Β #46771
classExample{privateget_foo(){returnMath.random()<0.5 ? "a" : "b";}bar(){if(this._foo==="a"){console.log("got 'a'");// this error should not occur:if(this._foo==="b"){console.log("lucky case, got 'b' too");}}}}classSpan{getend(){returnthis.start+this.length}constructor(publicstart: number,publiclength: number){}}constspan=newSpan(4,2);if(span.end==6){span.length+=1;// same here:if(span.end==7){console.log("worked");}}
π Actual behavior
An error occured because TypeScript thinks this._foo/span.end doesn't change until that if-check, but in these examples it does.
Activity
MartinJohns commentedon Nov 11, 2021
Another duplicate of #9998.
fatcerberus commentedon Nov 11, 2021
For the record: TypeScript makes no distinction between getters and plain properties at the type level.
typescript-bot commentedon Nov 13, 2021
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.