Skip to content

Function.prototype.bind doesn't read all overloadsΒ #48199

Closed
@youneshenni

Description

@youneshenni

Bug Report

πŸ”Ž Search Terms

bind overload signature

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about bind and method overload

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

    method(x:number): string;
    method(x:string): number;
    method(x:string | number): string | number {
        if (typeof x === 'string') return 0;
        return '';
    }
    method1: () => string;
    method2: () => number;

    constructor() {
        this.method1 = this.method.bind(this, 0);
        this.method2 = this.method.bind(this, '');
    }
}

πŸ™ Actual behavior

in method1's definition, typescript only reads one of the two method signatures (the first one) when you use bind on it.

πŸ™‚ Expected behavior

TypeScript should read all the available signatures when you call the bind method on your method. Because that's the purpose of method overloads.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions