microsoft / microsoft/TypeScript

Dead return statements in a generator should offer a did-you-mean-yield codefix

Open
#32,235 8 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Experience Enhancement Suggestion
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.