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

bug: wrapper types do not maintain function types for function overloads #17

Open
rexfordessilfie opened this issue Jul 6, 2023 · 0 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@rexfordessilfie
Copy link
Owner

rexfordessilfie commented Jul 6, 2023

Overview

Typescript allows you to specify overloads for functions. Ideally wrappers should maintain types for overloaded functions, however currently wrappers do not preserve overloaded function types.

declare function overloaded(arg1: string): string;
declare function overloaded(arg1: string, arg2: number): number;

type Overloaded = typeof overloaded
           // ^? { (arg1: string): string, (arg1: string, arg2: number): number }


const basicOverloaded = basic(overloaded)
           // ^? (arg1: string, arg2: number) => number

In the above, the overloaded type of overloaded is not preserved. Instead, only the last defined overload prevails. In the playground link modify the order of the overloads to notice this.

Playground Link

Links

The above issue was discovered on Twitter.

It is also related to the following open issues on Typescript:

@rexfordessilfie rexfordessilfie added bug Something isn't working help wanted Extra attention is needed labels Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant