Answers for "use function passing value as type typescript"

4

pass function as argument typescript

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
0

ts types passing functions

function foo(callback: Function) {
  console.log('foo() function called!');
  callback();
}
Posted by: Guest on April-07-2022

Code answers related to "use function passing value as type typescript"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language