microsoft / microsoft/TypeScript
Dead return statements in a generator should offer a did-you-mean-yield codefix
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.0.0-dev.201xxxxx
Search Terms: yield return generator
Currently it is possible to have the following code:
Code
async function *myGeneratorFunction(): AsyncIterableIterator<number> {
return 1;
return 2;
return 3;
}
Expected behavior:
A generator function that yields numbers 1 - 3
Actual behavior:
No syntax/runtime error but due to a human mistake the generator function is useless.
I copy/pasted an existing generator function, deleted the body with the new implementation and mistakenly used return instead of yield.
It would be nice if TypeScript could warn when it's encountering a return with an actual value inside a generator function.
It makes no sense to return a value.
Could be combined with a codefix in the IDE: Did you mean yield?
Playground Link:
Related Issues:
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
Inizia riproducendo l’esempio di async generator dell’issue ed esamina la gestione delle istruzioni return nei generatori da parte del compilatore e del language-service. Il lavoro è completo quando un return con valore in un generatore produce l’avviso previsto e l’IDE offre un codefix “Did you mean yield?”, con la copertura del comportamento dell’esempio.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100