Skip to content

Incorrent return type inference when using infer with generic function #48820

Closed
@user753

Description

@user753

Bug Report

type ApplyFn<Fn extends (item: any) => any, T> =
  Fn extends (item: T) => infer R ? R : never

type X = ApplyFn<(x: number) => string, number>

type X is string

type Fn = <T>(item: T) => {foo: T}
type Y = ApplyFn<Fn, string>

type Y is {foo: unknown} but I have expected {foo: string}

🔎 Search Terms

infer generic function return type

⏯ Playground Link

Playground link with relevant code

Is there any workaround to solve this problem?

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