镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

noImplicitReturns does not take account of a never return #18841

Description

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.

Activity

  1. DanielRosenwasser commented on Oct 1, 2017

    @DanielRosenwasser
    Member

    If we did this, every single expression statement with a function call would need to tie into the control flow graph which would likely be prohibitively expensive, but we should discuss it anyway.

  2. weswigham commented on Oct 1, 2017

    @weswigham
    Member

    Ron Buckton (@rbuckton) started looking into expanding flow control analysis to allow it to operate for throw expressions in #18798, so we're already looking into it.

  3. rbuckton commented on Oct 2, 2017

    @rbuckton
    Contributor

    Brian Terlson (@bterlson) mentioned a similar issue, wanting to be able to use process.exit(), but I don't think never is the correct type for this case.

  4. mhegazy commented on Oct 4, 2017

    @mhegazy
    Contributor

    This is a duplicate of #10470. The main issue really here is how these two features are implemented. implicit return checks happen earlier in the binder. where as control flow analysis happens later on when we are checking. merging the two is not a trivial task.

  5. added
    DuplicateAn existing issue was already created
    and removed
    SuggestionAn idea for TypeScript
    on Oct 4, 2017
  6. mhegazy commented on Oct 19, 2017

    @mhegazy
    Contributor

    Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

  7. ethanresnick commented on Feb 12, 2018

    @ethanresnick
    Contributor

    Is there a remaining open issue to track this? If not, should there be? I realize it's hard to implement, but maybe it's worth keeping open as a request? (#10470 has also been closed.)

  8. RyanCavanaugh commented on Feb 12, 2018

    @RyanCavanaugh
    Member

    Ethan Resnick (@ethanresnick) We'd prefer that open issues be actionable rather than serve as an infinite-scroll TODO list. Issues don't need to be open for us to be able to see activity on them

  9. locked and limited conversation to collaborators on Jul 3, 2018
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

    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