Skip to content
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

Generic type argument cannot be inferred by nested callback return type #9660

Closed
Igorbek opened this issue Jul 13, 2016 · 3 comments
Closed

Comments

@Igorbek
Copy link
Contributor

Igorbek commented Jul 13, 2016

TypeScript Version: 1.8.10

Code

declare function a<T>(f: (x: T) => ((y: T) => T)): T;

a<number>(x => y => 1); // works
a(x => y => 1);         // infers T as { }
a<string>(x => y => 1); // error, as expected

Expected behavior:
In a(x => y => 1), T is inferred as number based on nested callback return type.
As shows a<string>(x => y => 1) example, the just cannot be anything else.

Actual behavior:
In a(x => y => 1), T is inferred as { }.

@thorn0
Copy link

thorn0 commented Jul 13, 2016

@thorn0
Copy link

thorn0 commented Jul 13, 2016

You can simplify your issue:

declare function a<T>(f: (x: T) => T): T;

a<number>(x => 1); // works
a(x => 1); // infers T as { }

@Igorbek
Copy link
Contributor Author

Igorbek commented Jul 13, 2016

Thanks, then it's dup of #9659. Closing this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants