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

Broken overloads with type inference on callbacks #33271

Closed
millsp opened this issue Sep 5, 2019 · 1 comment
Closed

Broken overloads with type inference on callbacks #33271

millsp opened this issue Sep 5, 2019 · 1 comment

Comments

@millsp
Copy link
Contributor

millsp commented Sep 5, 2019

TS fails to remember the overloaded types and picks the last one by default, breaking the overload usability (in practice) when using callbacks. Let's take a simple example to make this more clear:

EDIT: Which seems to be a limitation of the typeof operator.

TypeScript Version: 3.7.0-dev.20190905

Search Terms: callback, inference, overloads

Code

declare function fn(a: string)
declare function fn(a: string, b: number)
declare function fn(a: object, b: number, c: object)

declare function promisify<Fn extends (...args: any) => any>(fn: Fn): (...args: Parameters<Fn>) => Promise<ReturnType<Fn>>

const promisedFn = promisify(fn)

const test0 = promisedFn('hello') // error
// only allows fn(a: object, b: number, c: object)

Expected behavior:
There shouldn't be any error. Maybe we could treat overloads as unions?

Actual behavior:
TypeScript picks that last overload only

Playground Link:

Related Issues:

@millsp
Copy link
Contributor Author

millsp commented Sep 5, 2019

Closing in favor of #598

@millsp millsp closed this as completed Sep 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant