Summary
A parenthesized / as-cast assignment target bypasses the const immutability check entirely. The binding is mutated and no TypeError is thrown.
Repro
const c = 1;
(c as any) = 9;
console.log("const after cast-assign:", c);
|
result |
| node 26 |
TypeError: Assignment to constant variable. |
perry main @ 0960415 |
prints const after cast-assign: 9 |
Verified on a clean origin/main build.
Why it matters
The const-binding immutability check is attached only to the bare-identifier assignment path; wrapping the LHS in parentheses or a TS cast routes around it. This is a silent wrong answer — a const is observably mutated with no diagnostic.
Related: #3571 (strict-mode unresolvable assignment / lexical declaration errors) covers the same area, but its other cases now pass; this one does not.
Summary
A parenthesized /
as-cast assignment target bypasses theconstimmutability check entirely. The binding is mutated and noTypeErroris thrown.Repro
TypeError: Assignment to constant variable.main@ 0960415const after cast-assign: 9Verified on a clean
origin/mainbuild.Why it matters
The const-binding immutability check is attached only to the bare-identifier assignment path; wrapping the LHS in parentheses or a TS cast routes around it. This is a silent wrong answer — a
constis observably mutated with no diagnostic.Related: #3571 (strict-mode unresolvable assignment / lexical declaration errors) covers the same area, but its other cases now pass; this one does not.