Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot set readonly property in IIFE #60413

Open
medikoo opened this issue Nov 4, 2024 · 3 comments Β· May be fixed by #60416
Open

Cannot set readonly property in IIFE #60413

medikoo opened this issue Nov 4, 2024 · 3 comments Β· May be fixed by #60416
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@medikoo
Copy link

medikoo commented Nov 4, 2024

πŸ”Ž Search Terms

"readonly", "iife"

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

No response

πŸ’» Code

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:

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

@MartinJohns
Copy link
Contributor

MartinJohns commented Nov 4, 2024

Essentially another duplicate of #9998. #58729 would likely fix this. This was nonsense, as pointed out by jcalz.

@jcalz
Copy link
Contributor

jcalz commented Nov 4, 2024

@MartinJohns aren’t IIFEs already inlined for CFA? I’m guessing initialization of readonly fields 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/deferred would make sense there either.)

@MartinJohns
Copy link
Contributor

You're right, my mistake. I swear I saw this issue before, but can't find it. :-/

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels Nov 4, 2024
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
4 participants