-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Unintuitive error message with 'unreachable' code #10991
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
Comments
I think this is the same as #10989. Not sure what would be a better error message... the issue is not that the compiler decided that this condition is unreachable, it is just that the type has been narrowed down in a way to make this comparison invalid. |
I should add, we are open to suggestions on making this better. |
The word that would helped me here would have been 'superfluous'. But I understand that crafting a good error message here is hard since you treat it as a type checking problem (e.g. key in that position can never have the value Keys.Tab) whereas for the user it looks like a 'flow analysis' problem. I will think if I can come up with something that would have helped me here. The problem I see is that 2.0 users seeing this problem will not have your compiler internal backgrounds :-) |
I guess when the left hand side is a There could be all sorts of logic errors that result in a |
The problem is that there's no If we wanted to get really fancy, when this kind of check fails, we could recompute the relation using the original declared types instead of the narrowed types. If that relation succeeded, then the error message could say something like
|
@RyanCavanaugh's proposal looks better than what we have today. A PR would be appreciated. |
+1 for @RyanCavanaugh proposal. Although I would leave the 'Do you have a logic error' out. |
TypeScript Version: 2.0.02
Code
On line 13 you get an error message that === can't be applied as an operator. Took me quite some time to find out that the same comparison was above (the real code was a little bit more complicated) and was leaving the function.
The text was updated successfully, but these errors were encountered: