microsoft / microsoft/TypeScript

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

Aperta
#45,712 1 commento 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia dal repro di Playground collegato e verifica come il target ES5 segnala la diagnostica per super.styles statico. Conferma che la modifica mantenga il comportamento non statico esistente consentendo al contempo il caso del getter statico, quindi verifica che la diagnostica non venga più mostrata per l'esempio.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, typescript
Ambito
compilers
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.