Skip to content

Cannot set readonly property in IIFEΒ #60413

Closed
@medikoo

Description

@medikoo

πŸ”Ž 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions