Answers for "typescript pass a function as an argunetn"

2

typescript pass a function as an argunetn

class Foo {
    save(callback: (n: number) => any) : void {
        callback(42);
    }
}
var foo = new Foo();

var strCallback = (result: string) : void => {
    alert(result);
}
var numCallback = (result: number) : void => {
    alert(result.toString());
}

foo.save(strCallback); // not OK
foo.save(numCallback); // OK
Posted by: Guest on June-30-2020

Code answers related to "typescript pass a function as an argunetn"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language