Skip to content

Unable to use super getters/setters when targeting ES5 #15842

Closed
@nomaed

Description

@nomaed

TypeScript Version: 2.3.2

Code

A perfectly valid and working JS code (ES2015), when transpiled down to ES5, causes typescript to output an error "Only public and protected methods of the base class are accessible via the 'super' keyword" on super.prop access in child class Bar.

According to issue #11575 I understand that this is due to regular properties not being part of the prototype, but getters and setters are on the prototype in the transpiled code.

No errors are reported when targeting ES2015.

class Foo {
    private _prop;

    get prop() { return this._prop; }
    set prop(value) { this._prop = value; }
}

class Bar extends Foo {
    constructor() {
        super();
    }

    get prop() {
        return `parent + ${super.prop}`; // error here
    }

    setProp() {
        super.prop = 'foofoo';  // error here
    }

}

const bar = new Bar();
bar.setProp();
console.log(bar.prop);

TS Playground link

Expected behavior:
This should be transpiled down correctly to ES5.
Just like it works using Babel as can be seen in the repl here

Actual behavior:
Error: Only public and protected methods of the base class are accessible via the 'super' keyword.

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