microsoft / microsoft/TypeScript
Polymorphic `this` and Generics
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
First, thank you team for polymorphic this. It is really handy!
I think I ran into a case though that I am finding challenging, when I need to return a this, but the generics might have changed. For example:
class A<T> {
private items: T[] = [];
map<U>(callback: (item: T, idx: number, a: this) => U): this {
// boring implementation details
});
}
Where I want to be able to change the generic type for the class with a function, but I will be contracting to return the "current" class, but I want to guard different generics. The following seems logical to me, but doesn't appear to be currently supported:
class A<T> {
private items: T[] = [];
map<U>(callback: (item: T, idx: number, a: this) => U): this<U> {
// boring implementation details
});
}
Where if no generics arguments are supplied, it is inferred to be the current ones, where as if they are supplied they are substituted.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Das Issue beschreibt eine vorgeschlagene Interaktion zwischen polymorphem this und der Substitution generischer Typen, nennt jedoch keine Implementierungsdateien, Tests oder Einstiegspunkte. Beginnen Sie damit, die Behandlung von polymorphem this und der generischen Instanziierung im Compiler zu lokalisieren; als erledigt gilt die Aufgabe, wenn das angeforderte Verhalten von this<U> mit den angegebenen Inferenz- und Substitutionsregeln unterstützt und durch Tests abgedeckt ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100