Skip to content

Poor inference for argument types in generic arrow function #17505

Closed
@Nathan-Fenner

Description

@Nathan-Fenner
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Won't FixThe severity and priority of this issue do not warrant the time or complexity needed to fix it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions