Skip to content
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

Loosen restriction on requiring return expressions when a throw is used instead #1042

Closed
danquirk opened this issue Nov 3, 2014 · 7 comments
Labels
Help Wanted You can do this Suggestion An idea for TypeScript

Comments

@danquirk
Copy link
Member

danquirk commented Nov 3, 2014

Per #947, we currently require a return expression in a non-void returning function unless the first and only expression is a throw statement. This is basically an exemption to allow for throw new Exception('Not Yet Implemented'). It seems reasonable to allow throwing further along in a block if we're willing to try to track control flow, at which point we could likely also check for appropriate return expressions from all branches.

@vladima
Copy link
Contributor

vladima commented Nov 4, 2014

I have a branch with an implementation of simple control flow analysis that captures cases like this atop of new compiler. It is slightly out of date but I think it'll take less than a day to sync it

@RyanCavanaugh
Copy link
Member

We should treat throw as equivalent to return for the purposes of this check

@RyanCavanaugh RyanCavanaugh added Help Wanted You can do this and removed In Discussion Not yet reached consensus labels Aug 3, 2015
@RyanCavanaugh RyanCavanaugh added this to the Community milestone Aug 5, 2015
@Ptival
Copy link

Ptival commented Jun 24, 2016

Any update on this? I often use throw ...; and debugger; to close branches that should not happen and have no meaningful return values.

@RyanCavanaugh
Copy link
Member

The new control analysis work should make this issue obsolete. Have you tried typescript@next ?

@Ptival
Copy link

Ptival commented Jun 24, 2016

No, I'm stuck on the npmjs version. (1.8.10?)

Good to know then! :-)

@NaridaL
Copy link
Contributor

NaridaL commented Sep 20, 2017

@RyanCavanaugh I think this can be closed?

@RyanCavanaugh
Copy link
Member

Agree, thanks!

@mhegazy mhegazy removed this from the Community milestone Apr 26, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

6 participants