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
letten=10asconst;// no error reportsten+=2;ten-=2;ten*=2;ten/=2;ten**=2;ten%=2;ten|=2;ten&=2;ten^=2;ten>>=2;ten>>>=2;ten<<=2;// all errors as expectedten=ten+2;ten=ten-2;ten=ten*2;ten=ten/2;ten=ten**2;ten=ten%2;ten=ten|2;ten=ten&2;ten=ten^2;ten=ten>>2;ten=ten>>>2;ten=ten<<2;letpinkie='Pinkie'asconst;// no error reportpinkie+='Pie';// error as expectedpinkie=pinkie+'Pie';
Expected behavior:
Shorthand assignment to a literal type where the resulting assigned value may not always be of that literal type should generate a compile-time error likewise its expanded form.
Actual behavior:
There is no error report for using shorthand assignment operators that might store an invalid value for that literal type. But the expanded form of those operators works as expected.
Quick inline proposal: compute literal types expressions at compile-time so that ten * 2 would be of type 20 but not number or type of 'Pinkie' + 'Pie' expression would be 'PinkiePie' instead of string.
DanielRosenwasser
changed the title
No error report when using shorthand assignment operator with literal types.
No error report when using compound assignment operator with literal types.
Apr 6, 2019
TypeScript Version: 3.4.2
Code
Expected behavior:
Shorthand assignment to a literal type where the resulting assigned value may not always be of that literal type should generate a compile-time error likewise its expanded form.
Actual behavior:
There is no error report for using shorthand assignment operators that might store an invalid value for that literal type. But the expanded form of those operators works as expected.
Playground Link:
Klick me
Related Issues:
The text was updated successfully, but these errors were encountered: