microsoft / microsoft/TypeScript
Generic Type Alias Overloading
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
- variadic type alias
- Generic variadic Type Alias
- Generic Overload
- Generic Type Alias Overloading
Suggestion
Ability to either:
- overload generic type definitions
or - define variadic type parameters for generic type aliases. (not sure how this would work)
Use Cases
My specific, immediate need is to create a generic variable number of input type alias for Intersection. I could see other use cases though, and imagine others would find it useful.
The closest work around is if I define default type parameters, like:
type Intersection<A, B, C = {} , D = {}, E = {}, F = {}> = A & B & C & D & E & F;
// and use like
let foo: Intersection<{ prop1: number}, {prop2: string}>;
// it evaluates to
{ prop1: number } &
{ prop2: number } &
{ } &
{ } &
{ } &
{ }
Examples
With overloads, the above type could be declared like:
type Intersection<A , B> = A & B;
type Intersection<A , B , C> = A & B & C;
type Intersection<A , B , C , D> = A & B & C & D;
type Intersection<A , B , C , D , E> = A & B & C & D & E;
type Intersection<A , B , C , D , E , F > = A & B & C & D & E & F;
I am not sure of a good syntax for the variadic type, it also seems like it would have a more limited use.
Checklist
My suggestion meets these guidelines: ( I think )
- 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
Überprüfe die vorgeschlagenen Überladungen für generische Typaliase und die alternative Idee variadischer Typparameter in den Issue-Beispielen. Ermittle das beabsichtigte Verhalten der Typprüfung, die Syntax, die Kompatibilitätsauswirkungen und den Umfang, bevor du Einstiegspunkte für Implementierung und Tests im TypeScript-Compiler identifizierst.
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
- Muss geklärt werden
- Anfängerfreundlichkeit
- 25/100