microsoft / microsoft/TypeScript
Allow inferring return type within a type guard in conditional types
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
typeguard conditional infer
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about (bug reporting)
⏯ Playground Link
Playground link with relevant code
💻 Code
This is simplified pretty heavily:
type InferredTypeGuard<TypeGuard> =
TypeGuard extends ((node: infer Input) => node is infer Output)
? (node: Input) => node is Output
: never;
🙁 Actual behavior
Error on infer Output:
A type predicate's type must be assignable to its parameter's type.
Type 'Output' is not assignable to type 'Input'.
'Input' could be instantiated with an arbitrary type which could be unrelated to 'Output'.(2677)
🙂 Expected behavior
TypeScript should allow a conditional type to infer the Output type within the type guard function's return type.
There's no other syntax I can find to do so, and I would have thought this would be the cleanest syntax. Not sure if bug report or feature request...
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 el ejemplo vinculado de TypeScript Playground y el tipo condicional simplificado que usa infer Input y infer Output. Traza la comprobación de asignabilidad del predicado de tipo que informa del error 2677 y determina cómo debería interactuar con ella la inferencia de tipos condicionales. Se considera terminado cuando el ejemplo se comprueba correctamente con los tipos de entrada y salida inferidos esperados, y existe cobertura de regresión para este comportamiento.
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
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 25/100