Skip to content

Generator .throw() causes a "Object is possibly 'undefined'" error during compilation with strictNullChecks is enabled #14431

Description

@dsole

TypeScript Version: 2.1.1

Code

// A *self-contained* demonstration of the problem follows...
function* myGen() {
  yield "foo";
}

let gen = myGen();

gen.throw(new Error("err"));

Compiled with the command
tsc --strictNullChecks --target ES6 example.ts

Expected behavior:
Compilation passes successfully.

Actual behavior:
example.ts(8,1): error TS2532: Object is possibly 'undefined'.

The error is on the gen.throw() line.
I have already tried putting undefined checks, assigning a local variable, trycatch blocks etc in the code but the error persists.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions