Skip to content

Default generic types are unused in ReturnType #48870

@ghost

Description

Bug Report

🔎 Search Terms

generic, default, unknown, infer

#48480 looked similar, but it was talking about the type of a function parameter's default value not being inferred, whereas this ticket is about a generic parameter with a default type not being used by infer.

🕗 Version & Regression Information

I tested against v4.4.4, 4.6.3, and nightly.

⏯ Playground Link

Playground link

💻 Code

function myFunc<A = number, B = string>(a: A, b: B) {
  return [a, b] as const
}

type myFuncType = typeof myFunc // <A = number, B = string>(a: A, b: B) => readonly [A, B] 

type myFuncReturnType = ReturnType< myFuncType > // readonly [unknown, unknown]

🙁 Actual vs Expected behaviour

I expect the type of myFuncReturnType to be readonly [number, string], but it's actually readonly [unknown, unknown], because the default generic type was not used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions