📜  typescript 将函数作为 argunetn 传递 - TypeScript 代码示例

📅  最后修改于: 2022-03-11 14:48:29.986000             🧑  作者: Mango

代码示例1
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