Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

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
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #typescript #pass #function #argunetn
ADD COMMENT
Topic
Name
9+8 =