microsoft / microsoft/TypeScript
Dead return statements in a generator should offer a did-you-mean-yield codefix
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
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:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the async generator example from the issue and inspect the compiler and language-service handling of return statements in generators. The work is done when a valued return in a generator produces the intended warning and the IDE offers a “Did you mean yield?” codefix, with coverage for the example behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100