microsoft / microsoft/TypeScript
Preserve ordered yield types when no logic is involved
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
🔍 Search Terms
yield ordered return 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
Make types more definite for each yielded return value in a generator function
📃 Motivating Example
Right now, if I do this:
function* work() {
yield 1;
yield 'test';
return [123];
}
Right now this gives:
const g = work();
g.next().value // string | number | number[]
g.next().value // string | number | number[]
g.next().value // string | number | number[]
But since there's no logic/branching/etc, it would be more helpful to me to have:
const g = work();
g.next().value // number
g.next().value // string
g.next().value // number[]
💻 Use Cases
Sometimes I want to use a function generator to represent a series of steps that I want to examine (whether at runtime or during testing, etc) before deciding whether to continue. In other words, I want to break up a function into a series of "pauseable" steps.
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
El issue no nombra archivos, pruebas ni puntos de entrada. Empieza validando los ejemplos de generadores y revisando el caso de uso enlazado de Stack Overflow. Se considera terminado cuando los resultados sucesivos del generador exponen los tipos ordenados de yield y return sin cambiar el comportamiento del runtime de JavaScript.
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