Skip to content

Invalid code typechecks in generators with strictNullChecks #22290

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

Closed
undeadcat opened this issue Mar 2, 2018 · 0 comments
Closed

Invalid code typechecks in generators with strictNullChecks #22290

undeadcat opened this issue Mar 2, 2018 · 0 comments
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@undeadcat
Copy link

TypeScript Version: 2.8.0-dev.20180302

Search Terms: generator, yield, strictNullChecks, typechecking

Code

function* myGenerator(): IterableIterator<number> {
  yield;
  yield 2;
}

for (let n of myGenerator()) {
  let number: number = n;
  console.log(number);
}

tsconfig.json:

{
  "compilerOptions": {
    "target":"es6",
    "strictNullChecks": true,
  }
}

Expected behavior:
I would expect yield; (without expression) to be forbidden if the generator return type (IterableIterator<number>) doesn't allow undefined.

Actual behavior:
This compiles fine, prints 'undefined', '2' (we're essentially allowing undefined to be assigned to non-nullable number).

Playground Link: link

@ghost ghost added Bug A bug in TypeScript Fixed A PR has been merged for this issue labels Mar 2, 2018
@ghost ghost closed this as completed in #22297 Mar 8, 2018
@mhegazy mhegazy added this to the TypeScript 2.8 milestone Mar 9, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

2 participants