-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Intersected function type returns only first constituent's return type #10508
Comments
this is covariance, right? dupe of #1394? |
declare const fooAB: {
(): A;
(): B
}; |
@mhegazy I understand that the current behavior is practical, but the only way a function could actually implement the intersection would be by returning a value of |
The compiler has no way of merging signatures in the general case. this one seems simple enough, but what happens if there are parameters involved, what if they have different count, what if one of them is generic, what if the parameter types do not agree.. for instance |
@mhegazy I agree that's not correct specifically because the functions have different parameter types. This means that using the union of each corresponding parameter is not accurate. Interestingly though, this also means that there is a way to select the overload that you want, so I don't think these signatures need to be merged. Obviously it's not a trivial problem. I think the intuitive behavior would be to only merge signatures when they match exactly in arity and parameter types. My reasoning is that there's no way to statically select and thus differentiate between the different signatures that are available without using a type assertion. |
TypeScript Version: 1.8/Playground
Code
Expected behavior:
ab
has typeA & B
Actual behavior:
ab
has typeA
Perhaps this is being treated as an overloaded call signature, and
() => A
just happens to be first. If this is by design, it would be great to learn about any known workarounds.cc @kevinder
The text was updated successfully, but these errors were encountered: