Skip to content

noImplicitReturns misidentifies generator return as function return when strictNullChecks is false #20299

Closed
@trxcllnt

Description

@trxcllnt

TypeScript Version: 2.6.1 - 2.7.0-dev.20171128

Code:

// index.ts
function* testGenerator() {
    if (Math.random() > 0.5) {
        return;
    }
    yield 'hello';
}

/* tsconfig.json
{
    "files": ["index.ts"],
    "compilerOptions": {
        "lib": ["esnext"], "target": "ESNEXT", "module": "es2015",
        "strictNullChecks": true,
        "noImplicitReturns": true
    }
}
*/

Expected behavior:

No errors due to the generator's early return, regardless of whether strictNullChecks is true or false.

Actual behavior:

  • No errors when strictNullChecks is true
  • The following error when strictNullChecks is false:
    index.ts(3,9): error TS7030: Not all code paths return a value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issueHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions