Type inference when a function is overloaded and the input param is a union of possible inputs #14337
Labels
Working as Intended
The behavior described is the intended behavior; this is not a bug
If we define a function and two interfaces like this:
I would like to be able to call the function like this
And have the return type be A | B. it seems to me this is logicaly consistent. No idea if it is hard to implement.
Syntactic
Does not change the syntax.
Semantic
Error TS2345 Argument of type '"A" | "B"' is not assignable to parameter of type '"B"'.
Type '"A"' is not assignable to type '"B"'.
The compiler is checking if all possible types of input match all the overloads, when in fact we just need
each type to match a single overload.
Emit
No change past the point of inference.
Compatibility
Should not break anything as this example code does not compile at the moment
Other
Can the feature be implemented without negatively affecting compiler performance?
Might even make it marginally faster as we can stop checking when we find the first overload matching the first type in the union and move on to the next.
The text was updated successfully, but these errors were encountered: