Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check return type inside generators #23571

Closed
wants to merge 1 commit into from
Closed

Check return type inside generators #23571

wants to merge 1 commit into from

Conversation

agentcooper
Copy link
Contributor

Fixes #18726.

I saw another pull request for this only after I did my fix and mine seems somewhat lighter (I maybe missed something).

Test case

async function* makeGenerator(): AsyncIterableIterator<number> {
  yield 1;
  yield 2;
  yield 3;
  yield 4;
  return "abc";
}

async function pull(gen: AsyncIterableIterator<number>) {
  const { done, value } = await gen.next();
  console.log(value);
  if (!done) {
    await pull(gen);
  }
}

pull(makeGenerator());

Command

node built/local/tsc.js --lib 'esnext,esnext.asynciterable' hello.ts

Before

No errors.

After

hello.ts:6:3 - error TS2322: Type '"abc"' is not assignable to type 'number'.

6   return "abc";
    ~~~~~~~~~~~~~

@msftclas
Copy link

msftclas commented Apr 20, 2018

CLA assistant check
All CLA requirements met.

@mhegazy mhegazy requested a review from rbuckton April 20, 2018 17:30
@mhegazy
Copy link
Contributor

mhegazy commented Apr 20, 2018

@rbuckton can you take a look.

@agentcooper
Copy link
Contributor Author

@mhegazy @rbuckton gentle ping

@agentcooper
Copy link
Contributor Author

@rbuckton can you please take a look at this one?

@mhegazy
Copy link
Contributor

mhegazy commented May 14, 2018

Please see my response in #18726 (comment)

@mhegazy mhegazy closed this May 14, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Constrain return statements in generator functions.
3 participants