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
varx: string|number;// no error, x is number in else branchvarr4=typeofx==="string" ? x.substr : x.toFixed;// error, x is string|number in else branchvarr5=typeofx==="string"&&typeofx==="string" ? x.substr : x.toFixed;
Same behavior occurs in if/else. I believe the error is this logic in narrowTypeByAnd:
// The assumed result is false. This means either the first operand was false, or the first operand was true// and the second operand was false. We narrow with those assumptions and union the two resulting types.returngetUnionType([narrowType(type,expr.left,/*assumeTrue*/false),narrowType(narrowType(type,expr.left,/*assumeTrue*/true),expr.right,/*assumeTrue*/false)]);
The text was updated successfully, but these errors were encountered:
first case narrowType(type, expr.left, /*assumeTrue*/ false), correctly yields number
when evaluating second branch we first narrow type assuming that check for lhs should succeed- this yields string. After that we'll try to narrow this type assuming that check for rhs fails - in process of doing this we'll invoke subtractPrimitiveTypes to subtract string from string. Intuitively this should return empty object type or union type with 0 constituents, however now subtractPrimitiveTypes works only for union types and for other kinds of types it will just return type itself - string.
Result type that will ultimately be returned will be number | string
Same behavior occurs in if/else. I believe the error is this logic in narrowTypeByAnd:
The text was updated successfully, but these errors were encountered: