Skip to content

Poor inference for argument types in generic arrow function #17505

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

Closed
Nathan-Fenner opened this issue Jul 29, 2017 · 1 comment
Closed

Poor inference for argument types in generic arrow function #17505

Nathan-Fenner opened this issue Jul 29, 2017 · 1 comment
Labels
Won't Fix The severity and priority of this issue do not warrant the time or complexity needed to fix it

Comments

@Nathan-Fenner
Copy link
Contributor

Nathan-Fenner commented Jul 29, 2017

function onlyIdentity(id: <T>(x: T) => T) {
}

onlyIdentity((x) => x); // okay, as expected

onlyIdentity(<S>(x): S => x); // x gets inferred type "any"

It would be nice if the argument got the correct inferred type (S) from it's context as an argument to onlyIdentity.

In my use case, the return type is small and needs to be narrowed, so I want to specify it, but the argument types are very complex, so I'd prefer that they were inferred.

@mhegazy mhegazy added the Needs Investigation This issue needs a team member to investigate its status. label Aug 29, 2017
@RyanCavanaugh RyanCavanaugh added Won't Fix The severity and priority of this issue do not warrant the time or complexity needed to fix it and removed Needs Investigation This issue needs a team member to investigate its status. labels Jul 23, 2019
@RyanCavanaugh
Copy link
Member

Functions with type arguments aren't subject to contextual typing; this doesn't seem to be a problem in general and would complicate type inference quite a bit to try to solve that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Won't Fix The severity and priority of this issue do not warrant the time or complexity needed to fix it
Projects
None yet
Development

No branches or pull requests

3 participants