-
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
Warning when writing a generator function without any yield #13847
Comments
Accepting PRs for the rule: a generator function with a |
#14043 has a valid example, a default implementation for a generator. the alternative would be to implement a function that returns the generator protocol, but that seems overly verbose. |
In light of the discussion about errors vs warnings we should instead move this to tslint. |
Note: #30790 will address this only in cases where the return type is explicitly specified as |
TypeScript Version: 2.2.0-dev.20170126
Code
Expected behavior:
Some kind of notice that this generator function never actually yields anything.
Actual behavior:
Compiles, and runs for that matter, without error, just silently yielding nothing.
I just spent a couple of hours tracking down a bug here, where
return
was accidentally used instead ofyield
. I'll admit I'm only starting to learn about generator functions and their uses, so it may be entirely possible that there are generator functions that want to return, rather than yield, in some cases, but my understanding is that every generator function should yield at some point.Could we get a compiler warning for something like this? I'm not looking for a halt detector or anything :P just some kind of warning like "No 'yield' in reachable code," or something.
The text was updated successfully, but these errors were encountered: