Skip to content

Only the last overloaded signature is picked when passing an overloaded function to Array.map #55840

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
vfsfitvnm opened this issue Sep 23, 2023 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@vfsfitvnm
Copy link

πŸ”Ž Search Terms

"overload", "last overload", "is not assignable to parameter of type", "Array.map"

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.3.0-dev.20230923&ssl=2&ssc=1&pln=3&pc=1#code/CYUwxgNghgTiAEAzArgOzAFwJYHtVJxwAoA3KCZEALngGcMYtUBzAShvsZYG4BYAKFCRYCFOmx4CxMhWrxUyALYAjEDHbylqmH34CweevBgAGDgybMA2gF14AXnhWARFGcAaeM+XObAOkUoAAciAH0HAD4pMNZWbngAegT4HABrfUMMYwBGcy5rO0cXN09vXwDgokRCOMTktRgcGAEgA

πŸ’» Code

declare function foo(value: string): string;
declare function foo(value: number): number;

const r0: string[] = ["a", "b"].map(_ => foo(_)); // ok
const r1: string[] = ["a", "b"].map(foo); // error, number is inferred

πŸ™ Actual behavior

It looks like when foo is passed "directly" (that is without a wrapper arrow function), its signature is the last one that was declared. Swapping the first two lines works around the issue, indeed.

πŸ™‚ Expected behavior

It should iterate through all the possible overloads.

Additional information about the issue

No response

@MartinJohns
Copy link
Contributor

Sounds like a duplicate of #47571.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Oct 5, 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.

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