Skip to content

can not get correct params type when using Parameters to overloaded function #54721

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
LaamGinghong opened this issue Jun 21, 2023 · 2 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@LaamGinghong
Copy link

Bug Report

πŸ”Ž Search Terms

  • overloaded funciton
  • type
  • Parameters

⏯ Playground Link

https://www.typescriptlang.org/play?#code/LAKAlgdgLgpgTgMwIYGMYAIBiF0G9TroAUMAbjNAFzoDOUckA5gDToAOScSAtjQPzUkEAJ4BKaqQD2YACYFiZClBrUA2nQYQW6IcL4BdVfvHops0AF9QoKMLYZsABU48a6ALzpnXbjFhwaAB5sAD5QAHpwwkIAPT4gA

πŸ’» Code

interface Fn {
  (event: string, params?: any): void
  (events: [string, any?][]): void
}

type FnParams = Parameters<Fn>
//    ^?

πŸ™ Actual behavior

only get last case's type.

πŸ™‚ Expected behavior

get all cases's type

@fatcerberus
Copy link

Duplicate of #43731.

This is a known (and documented) design limitation:
https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#inferring-within-conditional-types

When inferring from a type with multiple call signatures (such as the type of an overloaded function), inferences are made from the last signature (which, presumably, is the most permissive catch-all case). It is not possible to perform overload resolution based on a list of argument types.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jun 22, 2023
@typescript-bot
Copy link
Collaborator

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

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants