microsoft / microsoft/TypeScript
Generic constraint is not validated in a recursive type
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
🕗 Version & Regression Information
- This is the behavior in every version I tried, starting from 4.1 where recursive conditional types were added
⏯ Playground Link
Playground link with relevant code
💻 Code
export type ComputeRangeLoose<
N extends number,
Result extends Array<number> = [],
> = Result['length'] extends N ? Result : ComputeRangeLoose<N, [...Result, Result['length']]>
type A = ComputeRangeLoose<{ foo: true }>
export type ComputeRangeStrict<
N extends number,
Result extends Array<number> = [],
> = N extends number
? Result['length'] extends N ? Result : ComputeRangeStrict<N, [...Result, Result['length']]>
: never
type B = ComputeRangeStrict<{ foo: true }>
🙁 Actual behavior
ComputeRangeLoose<{ foo: true }> allows to pass a type that is not related to number, throwing Type instantiation is excessively deep and possibly infinite.
ComputeRangeStrict<{ foo: true }> throws an expected Type '{ foo: true; }' does not satisfy the constraint 'number'
🙂 Expected behavior
Both ComputeRangeLoose and ComputeRangeStrict throw Type '{ foo: true; }' does not satisfy the constraint 'number'
As the issue is reproducible since 4.1, I'm pretty sure it was already mentioned somewhere however I failed to find a suitable issue
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 reproduciendo el problema en el TypeScript Playground enlazado usando los ejemplos ComputeRangeLoose y ComputeRangeStrict. Rastrea la comprobación de restricciones genéricas para tipos condicionales recursivos y verifica que ambas instanciaciones no válidas informen del diagnóstico de restricción esperado en lugar de una profundidad de instanciación excesiva.
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