-
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
Switch is considered exhaustive or not based on the code after it #18882
Comments
Currently, when an exhaustive |
Accepting PRs - when detecting whether the switch is "final", skip over any declarations that are hoisted (functions but not classes), declarations that are type-only (interface, type, const enum), or declarations that have no side effects (var) |
@RyanCavanaugh To make sure I understand correctly: Should a Also, is there any reason why we can't consider any top-level exhaustive switch to be "final"? Since an exhaustive switch will necessarily return along all code paths, any code after it should be unreachable and thus a function with a top-level exhaustive switch won't ever have an implicit return. |
If it's truly exhaustive (i.e. it has a |
@DanielRosenwasser The current logic that determines a Switch is exhaustive requires that the switch:
That seems at first glance to be more restrictive than your conditions. I'll take a look at implementing it so that functions with exhaustive switches never have implicit returns. |
PR Opened with the above logic #20063 |
thanks @charlespierce ! |
TypeScript Version: 2.5.3
Code
With
--noImplicitReturns
:1:
2:
3:
Expected behavior:
Either:
(1), (2), and (3):
Or:
(1) and (3) compile.
(2):
Actual behavior:
(1) compiles.
(2) and (3):
Additional notes:
I'm not sure which is the correct behaviour, but right now it's inconsistent.
Originally posted as a question here: https://stackoverflow.com/q/46518643/785745
The text was updated successfully, but these errors were encountered: