Skip to content
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

Incorrectly inferred call signature #60388

Closed
boris-kolar opened this issue Nov 1, 2024 · 3 comments
Closed

Incorrectly inferred call signature #60388

boris-kolar opened this issue Nov 1, 2024 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@boris-kolar
Copy link

boris-kolar commented Nov 1, 2024

πŸ”Ž Search Terms

call signature, overloaded call

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about call signature

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.7.0-dev.20241101#code/JYOwLgpgTgZghgYwgAgGIHt3IN4ChnIAUAHgFzICMAlOQEz5FnK03IDMuAvrrmAJ4AHFAGE4AGzEBlYAHMQcMAFcoEADwAVAHzIAvMnXIIxSCAAmAZyIA6GwPKgY0ZAAUqu7Q6cAlZAH5rtuSu7sg+5Oq8gigA6lDoIDLqUbrIohLScgrKahjo2gD0+Yx0bjrabEA

πŸ’» Code

interface Foo {
  (x: 1): 2
  (x: 2): 3
}

type CallSignature<T> = T extends (...p: infer P) => infer R ? (...p: P) => R : T
type WrongType = CallSignature<Foo> // (x: 2) => 3

πŸ™ Actual behavior

The inferred type is not compatible with actual type

πŸ™‚ Expected behavior

The inferred type should (at minimum) be compatible with actual type (ideally { (x: 1) => 2; (x: 2) => 3 }).

Additional information about the issue

No response

@MartinJohns
Copy link
Contributor

This is working as intended / a design limitation. See the documentation: 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.

@jcalz
Copy link
Contributor

jcalz commented Nov 1, 2024

see #26591 and other issues

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Nov 4, 2024
@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 Nov 7, 2024
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

5 participants