microsoft / microsoft/TypeScript

Return statement in iterator is not type checked

Open
#30,209 0 comments 1 reaction 1 assignee View on GitHub

@rbuckton is already working on this.

Since Mar 4, 2019.

Needs Investigation
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TypeScript Version: 5.3.2.

Search Terms: yield, return, iterator.

Code:

interface Result {
    foo: number;
}

function* gen(): IterableIterator<Result> {
    yield { foo: 1 };
    return { garbage: true }; // not checked
}

(function go(iterator) {
    const { value, done } = iterator.next();
    console.log(value);
    if (!done) {
        go(iterator);
    }
})(gen());

Expected behavior: type error on return statement.

Actual behavior: no type errors.

Playground Link: https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgAgEoQM4FcA2ZkDeAUMqcjAPYUBcyIWAtgEbQDcRAvkUTFiAmGAUQAKmQBzCCAAUASloBJSFDhMcEJdDhgKUADzpseAHyESZAJ7AIOACaFyVWgEZkHdmWRQIYLFBAO4nBQTHCStGBQWCjuyAD0cXQU+AgAFhAIANYQtpzc0rz8gsISFNLAytq6smaeCMIY+ATIAG5wONEANMi2wjHIALzIFVo6UAB0IBAAHmByHmT1IBgU6uM4FOLSbR0QsgukwDDI0gCEvVM1xJ6e4mUjKmP75qRcHLLSkjKy+0A

Related Issues: https://github.com/Microsoft/TypeScript/issues/26959.

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.