-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Type inference resulting in incorrect type for function result #14798
Comments
Note: it's valid to assign the value of a void-returning function, e.g. the following compiles: const v = functionReturningVoid(); |
@magnushiie function functionReturningVoid() {
}
function functionReturningNumber() {
return 0;
}
function returnValueFrom<R>(f: () => R): R {
return f();
}
const rVoid = returnValueFrom(functionReturningVoid); // ok
const rNumber : number = returnValueFrom(functionReturningNumber); // ok Or are you trying to illustrate some more generic problem? |
Ah, yes, this solves it. I thought I had a more generic instance where this would not be a solution, but I can't find it anymore. |
Constraints don't produce an inference site, so there's nothing to infer |
TypeScript Version: 2.2.1
Code
Expected behavior:
Compiles successfully.
Actual behavior:
Compiles with the above errors noted in comments.
The text was updated successfully, but these errors were encountered: