📜  传递函数作为参数打字稿代码示例

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

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