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

Function that always throws is not inferred as having never return type #16608

Closed
masaeedu opened this issue Jun 18, 2017 · 5 comments
Closed
Labels
By Design Deprecated - use "Working as Intended" or "Design Limitation" instead

Comments

@masaeedu
Copy link
Contributor

TypeScript Version: 2.5.0-dev.20170618

Code

function fail1() {
  throw new Error()
}

const fail2 = function () {
  throw new Error()
}

Expected behavior:
Inferred return type of both functions is never

Actual behavior:
Only the return type of the second function is never. The return type of fail1 is inferred as void.

@ahejlsberg
Copy link
Member

This is by design. We had it the way you suggest originally but I was too much of a breaking change. See #8767 for more details.

@ahejlsberg ahejlsberg added the By Design Deprecated - use "Working as Intended" or "Design Limitation" instead label Jun 19, 2017
@masaeedu
Copy link
Contributor Author

masaeedu commented Jun 19, 2017

@ahejlsberg Could we have an off-by-default compiler flag that unifies this behavior?

@basarat
Copy link
Contributor

basarat commented Jun 19, 2017

Perhaps only class methods should get void inference 🌹

@mhegazy
Copy link
Contributor

mhegazy commented Aug 17, 2017

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

@aluanhaddad
Copy link
Contributor

I really like @basarat's suggestion.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
By Design Deprecated - use "Working as Intended" or "Design Limitation" instead
Projects
None yet
Development

No branches or pull requests

5 participants