microsoft / microsoft/TypeScript
Generic Type Alias Overloading
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Esamina gli overload proposti per gli alias di tipo generici e l’idea alternativa dei parametri di tipo variadici negli esempi dell’issue. Determina il comportamento previsto del controllo dei tipi, la sintassi, le implicazioni di compatibilità e l’ambito prima di identificare i punti di ingresso per l’implementazione e i test nel compilatore TypeScript.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 25/100