microsoft / microsoft/TypeScript
Spreading tuple into generic/type arguments
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.3k
- Merge medio
- 2 d 4 h
- PR fusionados (30 d)
- 132
Descripción
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.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza revisando la propuesta y sus ejemplos sobre el comportamiento previsto de la expansión de argumentos genéricos. Se considera terminado cuando se admitan expansiones de tuplas en argumentos de tipo, incluido el truncamiento cuando la tupla es más larga y los elementos finales cuando es más corta, sin cambiar el JavaScript generado.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- compilers
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Activo
- Claridad
- Bien especificado
- Aptitud para principiantes
- 35/100