microsoft / microsoft/TypeScript
Generator functions which have a return type of a union of Iterator/AsyncIterator have a yield type of never
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
TypeScript Version: 3.7.2
Search terms: generator iterator asynciterator type union never
Code
example.ts
type NumberIterator = Iterator<number> | AsyncIterator<number>;
type NumberGenerator = Generator<number> | AsyncGenerator<number>;
function *numbers(): NumberIterator {
yield 1;
}
A type alias which is a union of Iterator and AsyncIterator is used as the return type of a synchronous generator.
Expected behavior:
Code compiles.
Actual behavior:
example.ts(5,11): error TS2322: Type '1' is not assignable to type 'never'.
If you replace NumberIterator with NumberGenerator as the return type the function above, the code correctly type-checks. Something is wrong here.
Playground Link:
The playground link won’t work because the playground doesn’t support async iterators yet (https://github.com/microsoft/TypeScript-Website/issues/15).
Related Issues:
#30790 Strongly-typed iterator PR
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
Reproduce el diagnóstico de TypeScript 3.7.2 de example.ts, comparando los tipos de retorno de NumberIterator y NumberGenerator. Lee el issue #30790 relacionado para conocer el contexto de los iteradores y verifica después que el generador síncrono con una unión de Iterator y AsyncIterator compile sin el error yield-type-never.
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
- Bien especificado
- Aptitud para principiantes
- 45/100