Closed
Description
Bug Report
π Search Terms
useDefineForClassFields override accessor with instance property (no results really, but related: #33509)
π Version & Regression Information
I'm in 4.1.3
β― Playground Link
π» Code
class Foo {
_foo: number = 1
get foo() {return this._foo}
set foo(v) {this._foo = v}
}
class Bar extends Foo {
foo = 123 // ERROR, although useDefineForClassFields is false
}
π Actual behavior
There is an error
π Expected behavior
There should be no error, because the legacy [[Set]] semantics are in play, and therefore it works as intended: the subclass calls the super class accessor.
It should desugar to:
class Foo {
constructor() {
this._foo = 1;
}
get foo() { return this._foo; }
set foo(v) { this._foo = v; }
}
class Bar extends Foo {
constructor() {
super();
this.foo = 123; // triggers accessor
}
}
which is very similar to the output that you see in the playground.
Also it doesn't work with declare
.