Skip to content

'super.prop' should only be allowed for accessors #42214

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

Open
ajafff opened this issue Jan 5, 2021 · 1 comment
Open

'super.prop' should only be allowed for accessors #42214

ajafff opened this issue Jan 5, 2021 · 1 comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@ajafff
Copy link
Contributor

ajafff commented Jan 5, 2021

Bug Report

πŸ”Ž Search Terms

super property access

πŸ•— Version & Regression Information

  • This changed in version v1.8.2

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

class Base {
    method() {}
    prop = 1;
    get accessor() { return 1 }
}

class Derived extends Base {
    fn() {
        super.method; // allowed, as expected
        super.accessor; // allowed for target >=ES2016, expected it to always be allowed
        super.prop; // allowed for target >=ES2016, expected it to always be disallowed, gives 'undefined' at runtime
    }
}

πŸ™ Actual behavior

For target <= ES5 both super.accessor and super.prop are an error, for target > ES5 both are allowed, although the runtime behavior is exactly the same. This change was introduced in #5860 because back then there was no (reliable) information whether a property was an accessor or a regular property. Now we have that information even in DTS files. The PR comments even mention that this change was not really correct.

Related: #24678 which was marked "Working as intended", although in the comments it was clearly stated that there should've been a compile error.

πŸ™‚ Expected behavior

Property access on super allows everything that resides on the prototype (methods and accessors) and disallows instance properties.
Same logic should apply to all target ES versions as the behavior is always the same.

@pbrennand-francis
Copy link

I just ran into this in Angular development and it took a long time to figure out what was wrong (e.g. dependency injection, etc...). Especially when there are multiple variables at play this would be extremely helpful to have the compiler catch the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

3 participants