Sitelet https://web.archive.org/web/20260121053620/https://github.com/microsoft/TypeScript/issues/57463
Skip to content

ReturnType returns unknown if function's return type is generic argument of the function (with default value) that has not been set #57463

@cts-tradeit

Description

@cts-tradeit

🔎 Search Terms

ReturnType, generic, default

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions ______ and _______
  • This changed in commit or PR _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because _______

⏯ Playground Link

No response

💻 Code

const func = <Return = string>(): Return {
   //
}

type ShouldBeNumber = ReturnType<typeof func<number>>; // number
type ShouldBeString = ReturnType<typeof func>; // unknown

🙁 Actual behavior

ReturnType returns unknown.

🙂 Expected behavior

ReturnType returns default type.

Additional information about the issue

This was encountered when trying to write this kind of function:

const invoker  = <Endpoint extends (...args: any) => any>(endpoint: Endpoint, ...parameters: Parameters<Endpoint>): ReturnType<Endpoint> {
    // Perform some logic before endpoint function is called

    return endpoint(...parameters);
}

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