microsoft / microsoft/TypeScript

Generators/Async Generators with TReturn type argument which extends undefined have a return method with a non-optional argument in 3.6.2

Open
#33,357 7 comments 0 reactions 1 assignee View on GitHub

@rbuckton is already working on this.

Since Sep 16, 2019.

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

Description

TypeScript Version: 3.6.2

Search Terms:
generator iterator return argument optional required

Code

function *gen(): Generator<number, number | undefined> {
  yield 1;
  return 2;
}

gen().return();

Expected behavior:
The argument passed to the return method should be optional. Not sure if this is possible with typescript.

Actual behavior:

file.ts(6,7): error TS2554: Expected 1 arguments, but got 0.
6 gen().return();
        ~~~~~~~~

  typescript/lib/lib.es2015.generator.d.ts:26:12
    26     return(value: TReturn): IteratorResult<T, TReturn>;
                  ~~~~~~~~~~~~~~
    An argument for 'value' was not provided.

Playground Link:

Playground is not available for 3.6.2

Related Issues:
#30790 Strongly typed iterator PR.
#32682 Other (async) iterator usability issues.
#33239 Trouble implementing async iterator interface in 3.6.2
#33241 Unable to use done property of IteratorResult to narrow types in typescript 3.6.2

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.