microsoft / microsoft/TypeScript
Type inference for async generators
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
Suggestion
It would be amazing if typescript could infer types from async generators.
The following is valid javascript, thus, I think, it should be valid typescript and type of x should be inferred.
Today it fails with Parameter 'x' implicitly has 'any' type.
async function forever(x) {
for await (const unused of x) {
void unused;
}
}
async function* test() {
for (;;) {
await something();
yield;
}
}
forever(test());
🔍 Search Terms
async generator, async iterator, type inference, infer types
✅ Viability 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, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
⭐ Suggestion
Treat type of x as "any async iterator would do" thus including any async generator function.
📃 Motivating Example
My own use... forever/background (async) processes/
💻 Use Cases
Today, I need to type this explicitly, which is unnecessarily verbose.
In the long run, it would allow composing async functions same as type inference helps composing plain functions today.
I get it that type inference for async iterables/iterators/generators opens a huge can of worms, like:
- type narrowing, like #36687 or in this vein
- yield expression return type #36967
- generator yielded type #32523
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 reportado de async generator y verifica el diagnóstico actual de implicit-any para forever(test()). No se nombran archivos, pruebas ni puntos de entrada; revisa las cuestiones relacionadas en #36687, #36967 y #32523. Se considerará terminado cuando estén definidos el alcance y el comportamiento de inferencia esperado para async iterators y generators.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- javascript, 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