microsoft / microsoft/TypeScript
Spreading tuple into generic/type arguments
Personne n'a encore pris cette issue.
- Langage dominant
- Go
- Étoiles
- 111k
- Forks
- 14.4k
- Merge moyen
- 1 j 19 h
- PR mergées (30 j)
- 117
Description
Search Terms
- spreading generic parameters
- generic parameter spread
- tuple generic spread
- spreading generic argument
- spreading typeArgument
- spreading type argument
Suggestion
Allow spreading of a tuple type into type arguments.
The idea is that a tuple of n elements gets spread into generic arguments with r arguments. If n is larger than r, only the first r items are used. If n is smaller than r it is possible to add elements after the spread argument. E.g.
function foo<A, B, C, D>() {
}
type ThreeType = [Foo, Bar, Baz];
foo<...ThreeType, Delta>();
Use Cases
I find myself repeating complex generic types. Ideally I could shorten lengthy repetition into a single type.
Examples
dialog.open takes three generic arguments, these have to be repeated each call. This makes the call less legible and reduces DRYness.
const dialogRef = this.dialog.open<
PrinterSelectDialogComponent,
PrinterSelectDialogData,
OfferProductPrinter>(
PrinterSelectDialogComponent,
{
data: {
printer,
},
},
);
After this proposal
export type PrinterSelectDialog = [
PrinterSelectDialogComponent,
PrinterSelectDialogData,
OfferProductPrinter,
];
const dialogRef = this.dialog.open<...PrinterSelectDialog>(PrinterSelectDialogComponent, {
data: {
service,
},
});
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.
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par examiner la proposition et ses exemples concernant le comportement prévu de la propagation des arguments génériques. La tâche est terminée lorsque les propagations de tuples dans les arguments de type sont prises en charge, y compris la troncature lorsque le tuple est plus long et les éléments de fin lorsqu’il est plus court, sans modifier le JavaScript généré.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- typescript
- Domaine
- compilers
- Type d'issue
- Fonctionnalité
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- Active
- Clarté
- Clairement spécifiée
- Accessibilité débutants
- 35/100