### 🔎 Search Terms "readonly", "iife" ### 🕗 Version & Regression Information - This is the behavior in every version I tried ### ⏯ Playground Link _No response_ ### 💻 Code ```ts class Foo { readonly bar: string = ""; constructor() { (() => { this.bar = "test"; })(); } } ``` ### 🙁 Actual behavior Fails with `Cannot assign to 'bar' because it is a read-only property.` error ### 🙂 Expected behavior Should work in exactly same way as: ```typescript class Foo { readonly bar: string = ""; constructor() { this.bar = "test"; } } ``` ### Additional information about the issue I assume that's expected for some reason, and I'd love to learn what are the logical grounds for that
Activity
MartinJohns commentedon Nov 4, 2024
Essentially another duplicate of #9998. #58729 would likely fix this.This was nonsense, as pointed out by jcalz.jcalz commentedon Nov 4, 2024
Martin Johns (@MartinJohns) aren’t IIFEs already inlined for CFA? I’m guessing initialization of
readonlyfields must be handled separately.(Also, I don't see how #58729 would help; at the very least, merely running that same code in a TS with some version of that PR in it doesn't seem to change anything. Not sure where adding
immediate/deferredwould make sense there either.)MartinJohns commentedon Nov 4, 2024
You're right, my mistake. I swear I saw this issue before, but can't find it. :-/