microsoft / microsoft/TypeScript
exactOptionsPropertyTypes - anomolous behavior with Tuples, options, and spreading.
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
- strictOptionalProperties #43947 #44548
- exactOptionalPropertyTypes
- Labelled Tuple Elements
- Optional Tuple Parameters (enabled with labeling)
- Variadic Tuple Types
🕗 Version & Regression Information
-
Spreading of Variadic Tuple types, as well as the ability to indicate final position optional parameters with labels, were introduced in ts 4.0. The noted behavior has been been present since then.
-
However, although there was hope it would be fixed with 4.4's exact
exactOptionsParameters, it was not.
⏯ Playground Link
💻 Code
type T1 = [x:number, x?:boolean]
const t11:T1 = [1,undefined] // EXCELLENT!! with exactOptionalPropertyTypes:true this became is an error.
const t12:T1 = [1,true]
const t13:T1 = [1]
type T2 = ['^',...T1,'$']
const t21:T2 = ['^',1,true,'$'];
const t22:T2 = ['^',1,undefined,'$']; // noerr - CLAIM - this SHOULD be an error
const t23:T2 = ['^',1,'$']; // err - CLAIM - this SHOULD NOT be an error
🙁 Actual behavior
In the above code, variable declaration for t22 is NOT an err.
In the above code, variable declaration for t23 IS an err.
🙂 Expected behavior
In the above code, variable declaration for t22 IS an err.
In the above code, variable declaration for t23 is NOT an err.
Even though with exactOptionalPropertyTypes , the T1 now no longer considers [number,undefined] to be a legal assignment, when T1 is spread into T2 the old behavior is used instead of the new behavior.
The documentation for exactOptionalPropertyTypes says
In TypeScript 4.4, the new flag --exactOptionalPropertyTypes specifies that optional property types should be interpreted exactly as written, meaning that
| undefinedis not added to the type:
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 con la reproducción vinculada de TypeScript Playground usando exactOptionalPropertyTypes y las asignaciones de tuplas T1/T2. Investiga cómo se comportan los elementos opcionales de las tuplas cuando se expanden variadic tuples y, después, verifica que t22 sea rechazado y t23 aceptado, mientras las comprobaciones existentes de T1 siguen siendo correctas.
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
- Bastante claro
- Aptitud para principiantes
- 35/100