Skip to content

Super call of non-method disallowed for static field disallowed unnecessarily #45712

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
rictic opened this issue Sep 3, 2021 · 1 comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@rictic
Copy link
Contributor

rictic commented Sep 3, 2021

Bug Report

🔎 Search Terms

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

static getter, setter, field, property

🕗 Version & Regression Information

Repro'd in stable, nightly, and TS 3.3.3

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

⏯ Playground Link

Playground link with relevant code

💻 Code

export {};

class SuperClass {
  static get styles() {
    return ['style'];
  }
}

class ChildClass extends SuperClass {
  static get styles() {
    return [...super.styles, 'additional style'];
  }
}

console.log(ChildClass.styles) // logs [['style'], 'additional style'] as expected

🙁 Actual behavior

When targeting ES5 we get the diagnostic Only public and protected methods of the base class are accessible via the 'super' keyword. on the super.styles.

This is a good diagnostic for the non-static case, because if super.styles was a property rather than an accessor then it probably wouldn't be accessible, as SuperClass.prototype.styles because it would be initialized in the constructor.

However a static field can reasonably be expected to have been initialized, and to be accessible at SuperClass.styles regardless of whether it's a property or an accessor.

🙂 Expected behavior

This should be allowed for static getters, as we have the super class object that we can access (unlike the non-static case, where we can't necessarily get at the original field if it wasn't a getter).

@andrewbranch andrewbranch added Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript labels Sep 3, 2021
@rictic
Copy link
Contributor Author

rictic commented Sep 4, 2021

Related to #338, but this issue is only concerned with static fields, where the concerns from that issue do not apply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants