Skip to content
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

Accessing base class field through super should be disallowed #48832

Closed
Josh-Cena opened this issue Apr 25, 2022 · 3 comments
Closed

Accessing base class field through super should be disallowed #48832

Josh-Cena opened this issue Apr 25, 2022 · 3 comments

Comments

@Josh-Cena
Copy link
Contributor

Josh-Cena commented Apr 25, 2022

Bug Report

🔎 Search Terms

Super, class, field, property

Related: #45712, #42215, which are about allowing legitimate accesses, while this is about disallowing illegal access.

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about classes

⏯ Playground Link

Playground link with relevant code

💻 Code

class A {
  a = 1;
}

class B extends A {
  calc() {
    // super.a has type number, but should be disallowed
    const a = super.a + 1;
  }
}

new B().calc();

🙁 Actual behavior

I'm allowed to access super.a, which is undefined at runtime.

🙂 Expected behavior

It should be forbidden, because super is an alias for instance.__proto__.__proto__, which is A.prototype, not an instance of A.

@Josh-Cena
Copy link
Contributor Author

I think this is due to the fact that TS has no concept (afaik) of the prototype chain. It thinks super means any instance of A.

@MartinJohns
Copy link
Contributor

Duplicate of #35314. Used search terms: super in:title

@Josh-Cena
Copy link
Contributor Author

Oh, oops, used too many keywords in my query. Thanks for pointing out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants