Skip to content

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

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
youneshenni opened this issue Mar 10, 2022 · 2 comments
Closed

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

youneshenni opened this issue Mar 10, 2022 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@youneshenni
Copy link

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.

@MartinJohns
Copy link
Contributor

Duplicate of #38353. Used search terms: bind overloads in:title

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Mar 11, 2022
@typescript-bot
Copy link
Collaborator

This issue has been marked as a '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