You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
functionu(): number{return;}
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:
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.
--noImplicitReturns will flag missing a return statement. the main issue today is that undefined is a valid value for any type, and return; is equivalent to return undefined; i would say this falls under the bucket of #185
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: