microsoft / microsoft/TypeScript
Unbounded arrays cannot be used as rest elements in a tuple type except at the end
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.4k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
Bug Report
🔎 Search Terms
A rest element must be last in a tuple type.
🕗 Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ for entries about rest elements and tuples.
Specifically, I tried it with 4.1.5 right now. Note that 4.0.5 behaved a bit differently (but still buggy), see below.
Note that the behavior is normal in versions ≤4.0, since that’s when non-final rest elements were allowed in tuples.
⏯ Playground Link
Playground link with relevant code
💻 Code
type Strings = [string, string];
type Numbers = number[];
type Unbounded = [...Strings, ...Numbers, boolean];
🙁 Actual behavior
The ...Numbers part generates an error: TS1256: A rest element must be last in a tuple type.
This exact code appears in TypeScript 4.0 release notes, thus presumably should work. (Search for “the resulting type becomes unbounded”.)
Note: I encountered something similar with 4.0.5 earlier. There, the non-final unbounded rest elements worked, but only via a type alias. They didn’t work with literal arrays in the tuple definition:
type Numbers = number[];
type Unbounded1 = [boolean, ...number[]]; // OK
type Unbounded2 = [...Numbers, boolean]; // OK
type Unbounded3 = [...number[], boolean]; // NOK
🙂 Expected behavior
The feature should work as documented. TypeScript should generate unbounded tuples type that work the “obvious” way.
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
Empieza con la reproducción enlazada en TypeScript Playground y el ejemplo de tipo tupla que muestra un elemento rest no acotado antes de un boolean. Sigue la validación de elementos rest del compilador para los tipos tupla y, a continuación, confirma que se acepta el ejemplo documentado de TypeScript 4.0 y que la tupla no acotada resultante se comporta como se espera.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- compilers
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 38/100