📜  typescript 参数函数类型 - TypeScript 代码示例

📅  最后修改于: 2022-03-11 14:48:34.007000             🧑  作者: 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