Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nomaed opened this issue May 15, 2017 · 1 comment
Closed

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

nomaed opened this issue May 15, 2017 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@nomaed
Copy link

nomaed commented May 15, 2017

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.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label May 15, 2017
@RyanCavanaugh
Copy link
Member

Duplicate #338 and many others; please search before logging new issues. Thanks!

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants