Skip to content

useDefineForClassFields is false, but overriding accessor with property still throws errorΒ #42563

Closed
@trusktr

Description

@trusktr

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

playground

πŸ’» 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.

Metadata

Metadata

Assignees

Labels

Working as IntendedThe behavior described is the intended behavior; this is not a bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions