镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

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

Description

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

Activity

  1. thorn0 commented on Jul 13, 2016

    @thorn0

    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 { }
  2. Igorbek commented on Jul 13, 2016

    @Igorbek
    ContributorAuthor

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

  3. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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