-
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
Reduce empty intersections to never #18210
Comments
The issue here is that intersection operator does not reduce empty types. e.g. in this example the type of I would like to keep this open for now, we have been getting this request often, and reducing these empty sets is what users expect any ways. |
Thanks for pointing out other issues talking about this! Yeah I think that would be a good way to solve this problem. Another one (not sure if it would be indeed different implementation-wise, or if it would require the same things to be modified), would be to improve the type refinement (i.e. changing the type after the I believe probably the suggestion to reduce never types is more general, and has more benefits (such as type readability), but just wanted to mention the other one in case it happens to have less impact or it is easier to implement, or just to consider it |
Had an offline discussion about with @ahejlsberg. this is not about reduction of the intersection, but about handling |
TypeScript Version: 2.4.0
Code
Expected behavior:
This should not raise an error, as I've already checked for existance of
foo
inc
, so the object infoo
should have bothbar
andbaz
as optional with their respective types. The type should be refined because I've already checked for the existance offoo
.Actual behavior:
Typescript shows an error when trying to access either
bar
orbaz
, as each property doesn't exist in one of the combinations of the intersection type, but the combination includesfoo
beingundefined
, which I checked above.The text was updated successfully, but these errors were encountered: