-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Generics, overloaded functions, and objects interact inconsistently #167
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
That is odd, I agree. The problem appears to be the way in which type inference interacts with assignability and overload resolution. We make inferences from index signatures only when the index signature kinds match (section 3.8.6 in spec), but we consider both string and numeric index signatures to be assignable to numeric index signatures with compatible types (section 3.8.4 in spec). The net outcome is that in your example that generates an error, we infer I think we need to change the inference rules to allow inferences to be made from both string and numeric index signatures to index signatures such that inference and assignability line up. |
Yes, I agree with @ahejlsberg's solution here. In general, the type argument inference relation should mirror the assignability relation as closely as possible. |
Type inference now supports inferring from string index signatures to numeric index signatures. Fixes #167.
Changing to spec issue. Section 3.8.6 needs to be updated to reflect that we now make inferences from both string and numeric index signatures to numeric index signatures. |
@georgewfraser Thanks for reporting. Fixed in the new compiler. |
Type inference exhibits strange behavior when you have an overloaded function with a generic that takes an object as an argument:
It seems to be just choosing the first overload.
The text was updated successfully, but these errors were encountered: