You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note that if I switch the order of the interface, it will only expect the other overload. I believe that typescript is overriding the previous value and not intersecting them
The text was updated successfully, but these errors were encountered:
The problem here is that interface I contains an overloaded function that is passed to ReturnType. When inferring the return type only the last overload is chosen, as specified here #21496:
When inferring from a type with multiple call signatures (such as the type of an overloaded function), inferences are made from the last signature (which, presumably, is the most permissive catch-all case). It is not possible to perform overload resolution based on a list of argument types (this would require us to support typeof for arbitrary expressions, as suggested in #6606, or something similar).
This is why the number input is ok but the string input is not, and this explains the behaviour you describe here:
Note that if I switch the order of the interface, it will only expect the other overload.
TypeScript Version: 3.4.0-dev.201xxxxx
Search Terms:
"mapped types", "overload", "intersection"
Code
Expected behavior:
argsObj.f.returnValue('1')
should not cause a type errorActual behavior:
argsObj.f.returnValue('1')
causes a type errorPlayground Link
Related Issues: Couldn't find anything
Note that if I switch the order of the interface, it will only expect the other overload. I believe that typescript is overriding the previous value and not intersecting them
The text was updated successfully, but these errors were encountered: