-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Infer return type of a function with provided argument types #26043
Comments
Looks like a duplicate of #6606 |
@mhegazy I guess #6606 is a much more complex feature request. Mine looks like only one case of "Call" type which was referenced by @treybrisbane. And if such Call type is implemented it will cover my issue also. But I thought my problem can be solved through new 2.8.* It would be great if you provided me with a link to an issue about such Call type if one exists. By the way, since #6606 is closed I'm not sure what do you mean by marking mine as a duplicate. Does it mean this issue won't be fixed? |
The underlying scenario is the same. #6606 proposed using The complexity in implementing either is applying overload resolution as a higher-order type operator. the overload resolution is extremely complicated process, that involved multiple passes and required multiple processes like contextual types, inference, and instantiations to interact. Enabling this, at least in the current compiler implementation, for higher order types is tantamount to rewriting the core of the compiler; something we are not looking forward to. You can seem my reply in #6606 (comment) as well. |
I believe that's not a bug.
const f1: Func<4, 4> = identity;
// @ts-ignore f2 failed
const f2: Func<4, 1> = identity;
const f3: Func<4, number> = identity;
const f4: Func<4, any> = identity;
const f5: Func<4, {}> = identity; As you can see the second argument of Func could be So
|
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
I'm trying to create something similar to native ReturnType type. In comparison to the later, it should also consider generic types of arguments.
I guess the idea will be clear from the code below.
If it can be done now - I'd be happy to receive some links. Otherways it'd be great to know if there are any plans to cover that behavior. In case it could be achieved by another not-implemented feature I'll be glad for the link to an issue to be able to track its progress.
TypeScript Version: 2.9.2
Search Terms: infer function return type
Code
Expected behavior:
I expect TS to be able to infer such return type
Actual behavior:
Return type is
{}
Playground Link: link
Related Issues:
The text was updated successfully, but these errors were encountered: