microsoft / microsoft/TypeScript
Generator functions which have a return type of a union of Iterator/AsyncIterator have a yield type of never
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Riproduci la diagnostica di TypeScript 3.7.2 da example.ts, confrontando i tipi restituiti da NumberIterator e NumberGenerator. Leggi la issue #30790 correlata per il contesto degli iteratori, quindi verifica che il generatore sincrono con un’unione di Iterator e AsyncIterator venga compilato senza l’errore yield-type-never.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 45/100