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
No error report when using compound assignment operator with literal types. #30783
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.
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.[/+]on Apr 6, 2019
Activity
Veetaha commentedon Apr 5, 2019
Quick inline proposal: compute literal types expressions at compile-time so that
ten * 2would be of type20but notnumberor type of'Pinkie' + 'Pie'expression would be'PinkiePie'instead ofstring.[-]No error report when using shorthand assignment operator with literal types.[/-][+]No error report when using compound assignment operator with literal types.[/+]DanielRosenwasser commentedon Apr 6, 2019
Potentially related to #13865, but I feel like we have another issue about this.
RyanCavanaugh commentedon Apr 9, 2019
Duplicate #14745
typescript-bot commentedon Apr 12, 2019
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.