Can I use TypeScript overloads when using fat arrow syntax for class methods?

You can write an inline type literal for the call signatures the function supports:

class TestOverloads2 {
    private status = "blah";
    public doStuff: {
        (selector: JQuery): void;
        (selector: string): void;
    } = (selector: any) => {
        alert(this.status);
    }
}

That’s sort of hideous, so you might want to extract it into an interface instead:

interface SelectByJQueryOrString {
    (selector: JQuery): void;
    (selector: string): void;
}

class TestOverloads3 {
    private status = "blah";
    public doStuff: SelectByJQueryOrString = (selector: any) => {
        alert(this.status);
    }
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)