microsoft / microsoft/TypeScript

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

Open
#45,712 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

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).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Playground repro and inspect how the ES5 target reports the diagnostic on static super.styles. Confirm the change preserves the existing non-static behavior while allowing the static getter case, then verify the diagnostic no longer appears for the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.