microsoft / microsoft/TypeScript

Subclass method is not allowed (TS2425) if the parent class has a property of type any with the same name

Aperta
#27,965 19 commenti 13 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

TypeScript appears to treat class methods as something fundamentally different from a class prototype property of type function. This is not in agreement with the standard semantics of ES6.

TypeScript Version: all versions, as far as I have been able to test.

Search Terms: method member property any parent class subclass

Code

class Super {
    prop: any;
}

class Derived extends Super {
    prop() {}
}

Expected behavior: should compile without a problem. Note that by the ES6 standard, the above definition of Derived is equivalent to the following, which TypeScript compiles without a problem:

class Derived extends Super {}

Derived.prototype.prop = function(){};

Actual behavior:

Error TS2425: Class 'Super' defines instance member property 'prop', but extended class 'Derived' defines it as instance member function.

Playground Link: https://www.typescriptlang.org/play/#src=class%20Super%20%7B%0D%0A%20%20%20%20prop%3A%20any%3B%0D%0A%7D%0D%0A%0D%0Aclass%20Derived%20extends%20Super%20%7B%0D%0A%20%20%20%20prop()%20%7B%7D%0D%0A%7D%0D%0A

Related Issues: I didn't find similar issues, although I started by looking for issues requesting for the ability to disable particular errors (TS2425 in this case). There are several (closed) issues in which such an ability is requested or suggested, but I believe the proper solution would be to bring TypeScript in agreement with ES6. After all, it claims to be a superset!

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 riproducendo l’esempio nel TypeScript Playground collegato e traccia il controllo che segnala TS2425 per una proprietà ereditata di tipo any rispetto a un metodo della sottoclasse. Confrontalo con l’assegnazione equivalente al prototipo descritta nell’issue. Il lavoro è completato quando la definizione della classe viene compilata senza TS2425, mentre i controlli di ereditarietà pertinenti rimangono intatti.

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

Valutazione

Stack tecnologico
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
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.