Skip to content Skip to sidebar Skip to footer

Typescript Optional Callback Parameter Does Not Match Anonymous Function Passed To It

I have a simple problem with my TS callbacks. I have a function like this ... //inside a class //function is supposed to optionally accept any callback function refreshConn

Solution 1:

This snippet seems to be working fine:

class MyClass {

    public refreshConnection(callback?: Function) {

        if (callback) {
            callback();
        }
    }
}

let obj = new MyClass();
obj.refreshConnection(() => { console.log('It works!'); });

Post a Comment for "Typescript Optional Callback Parameter Does Not Match Anonymous Function Passed To It"