-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Suggestion: disallow implicit return of undefined #2316
Comments
Definitely fits well within either of those two larger options. |
We should use this as an opportunity to look at code patterns in the wild -- how many JavaScript|TypeScript functions "intentionally" use an expressioned return and unexpressioned return in the same function body, especially in those with return type annotations. |
I understand that TypeScript's goal is to be a super set of JavaScript, so legal JavaScript is legal TypeScript. However, if I add types to my code, it is no longer JavaScript, and I would like TypeScript to help me fulfill the contract that the type usage represents. If I declare a return type on my function and that function ends with "return;", I would like TypeScript to see that as an inconsistency & point that out to me. |
|
It would be useful to be able to disallow an Explicitly Typed function/method from implicitly returning the value undefined.
One example function that would be detected and disallowed was given by @rolyp in #2176. In that example, running off the end of the function causes undefined to be returned implicitly.
Another example that should be caught is:
A flag for enabling this option could be named --noImplictReturnUndefined.
This suggestion fits in with the meta-bug in #274 and maybe #2176.
The text was updated successfully, but these errors were encountered: