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
letx: string|number=0;x+='';// ERROR(2,1): Type 'string' is not assignable to type 'number'.
Expected behavior:
Since this is ok
letx: string|number=0;x=x+'';
similarly (showing that this has to do with type-narrowing)
functionf(x: string|number){x+='';}
and finally TS allows string and number additions, thus I expect the original to also be accepted by the compiler.
Generally treating x = x + 1 and x += 1 differently from type checking perspective is surprising, but maybe this is byproduct of other designed behaviors.
Actual behavior:
Error - Type 'string' is not assignable to type 'number'.
The text was updated successfully, but these errors were encountered:
TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx)
Code
Expected behavior:
Since this is ok
similarly (showing that this has to do with type-narrowing)
and finally TS allows string and number additions, thus I expect the original to also be accepted by the compiler.
Generally treating
x = x + 1
andx += 1
differently from type checking perspective is surprising, but maybe this is byproduct of other designed behaviors.Actual behavior:
Error - Type 'string' is not assignable to type 'number'.
The text was updated successfully, but these errors were encountered: