Skip to content

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

@Igorbek

Description

@Igorbek

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 { }.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions