Skip to content

Default generic types are unused in ReturnType #48870

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ghost opened this issue Apr 28, 2022 · 3 comments
Closed

Default generic types are unused in ReturnType #48870

ghost opened this issue Apr 28, 2022 · 3 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@ghost
Copy link

ghost commented Apr 28, 2022

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.

@MartinJohns
Copy link
Contributor

This is working as intended. See #42064 (comment).

@andrewbranch andrewbranch added the Working as Intended The behavior described is the intended behavior; this is not a bug label Apr 28, 2022
@Harpush
Copy link

Harpush commented Apr 30, 2022

I believe typescript 4.7 will solve it with the new Instantiation expressions?
#47607

@typescript-bot
Copy link
Collaborator

This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

4 participants