Skip to content

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

@rexfordessilfie

Description

@rexfordessilfie

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions