microsoft / microsoft/TypeScript
Allow omission of generic type if its equal to the default type
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
Search Terms
generic, default, extends, equals, =
Suggestion
Allow the syntax extends = T in generics definition in place of extends T = T.
Currently
class Foo <T extends any = any> {}
Suggestion*
class Foo <T extends= any> {}
Use Cases
The problem of having to write <T extends any = any> revealed itself when I had a bit more complex type looking like keyof NetworkTransportProtocol that looked then somehow like this:
class Foo<T extends keyof system.NetworkTransportProtocol = keyof system.NetworkTransportProtocol> {}
which just was a lot of duplicated text.
class Foo<T extends= keyof system.NetworkTransportProtocol> {}
by reducing the duplicate information the whole syntax becomes better to read.
While I did focus on the default-case for class-generics. I believe this could also help with other definitions:
function foo <T extends=any>(bar: T) {}
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
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 nennt keine Implementierungsdateien oder Tests; beginne damit, TypeScripts Grammatik und Tests für generische Constraints und Standardtypen zu finden. Vergleiche die vorgeschlagene extends=-Syntax für Klassen- und Funktionsgenerics und ermittle anschließend das erforderliche Verhalten von Parser und Type-Checking. Als abgeschlossen gilt die Aufgabe, wenn ein akzeptiertes Design und eine erfolgreiche Testabdeckung für die vorgeschlagene Syntax vorliegen.
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