Skip to content

noImplicitReturns does not take account of a never return #18841

Closed
@daveholladay

Description

@daveholladay

TypeScript Version: 2.5.2

Code

function foo(): never {
    throw new Error()
}

function bar(): number {
    if (Math.random() > 0.5)
        return 1;

    foo();
    // compiler should realise we can't get here.
}

Expected behavior:
Compiles without warnings when compiled with --noImplicitReturns

Actual behavior:
error TS7030: Not all code paths return a value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions