Skip to content

Implementation of abstract properties doesn't care about readonly and/or writeonly propertiesΒ #62527

@AFatNiBBa

Description

@AFatNiBBa

πŸ”Ž Search Terms

abstract readonly implementation

πŸ•— Version & Regression Information

Tried in the playground on Nightly (v6.0.0-dev.20251002) and on v3.3.3333, there's no difference

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=3.3.3#code/FAb2EgEMCMGcBcBOkDG8AEKA2la3QILpjhRxKoaQBc6AdgK4C20ApogNzrc8-gD0-dADkA9hkStIAE1F0sATwgBfYBEHoAKgoAOrAMopEASx0ZZrWHQDkGFJEnp4AC0gYXx-Bau30xpjpYrEysdO7OrOiwrPDw7BDYuPgAQuisAB5xdNL4RCTgAOYx6JAAFACUxOiS8AyIdOgAjFzKvHwaAEpSsvJK4KoJcgjoWLREALz0rADu6MkVHBBYAHSQ6JMAHFxtO7ttAkJiaYiIoojopV24cjBB5WoDJDAIyGiYOHiExBBkL5TV3TkihKtEYLHYHAO6CuPUUKjUUO0ekMJjM6G8NjsDkiLjcTmcnnRoksmL8ASCITC+MiRVi8XAiU+qQyWRyX3y0SopQAbqDmGxEJUQOhlKQoQB1ExxIF9AYMoYYLDrKazeblRbgFZrTaQsVijRHdinc6lADiolE0nuyiAA

πŸ’» Code

{
	abstract class A {
		abstract a: number;         	// Not readonly
	}

	// TypeScript doesn't care that this doesn't implement the setter
	class B extends A {
		get a() { return 1; }       	// Readonly
	}

	const l: A = new B();
	l.a = 8;                        	// No error (Reasonable)

}

{
	abstract class A {
		abstract readonly a: number;	// Readonly
	}

	// TypeScript doesn't care that this doesn't implement the getter
	class B extends A {
		set a(v: number) { }			// Writeonly
	}

	const l = new B();
	l.a = 8;							// No error (Good)
}

πŸ™ Actual behavior

TypeScript only cares about the name of the implemented property and its type

πŸ™‚ Expected behavior

It should also care about whether it's readable and/or writable

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions