flow typing for eliminated parts of union types in default match case? #17844
Swoorup
started this conversation in
Feature Requests
Replies: 0 comments 1 reply
-
As a side note: the difference between the two is that the default case makes it also match and return |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In typescript I can do like the following:
Here,
x
is deduced to a union of"B" | "C"
.With scala 3 union unfortunately you can't do so at the moment. The following fails to compile:
This will lead people to instead use
asInstanceOf
which is bad imo. You can still make it typesafe if you annotate the last type, without warnings likeBut it would be nice, if scala was able to auto deduce the type of
x
toInt | Boolean
, leading to more natural code and less usage ofasInstanceOf
.If there was a condition on the pattern match, we could retain the current behavior as is.
Beta Was this translation helpful? Give feedback.
All reactions