我的功能如下:
.add({a: 1, b: 2}, function (msg, reply) {
reply({z: msg.z})
})
它试过这样的事情:
interface SenecaMethods {
add: (patern: object, HERE SHOULD BE CALLBACK) => object;
}
如何为此定义类型?
答案 0 :(得分:0)
为add
定义类型的方式相同 - 函数类型对于回调看起来与对任何其他类型的函数相同。把它放在括号内:
interface SenecaMethods {
// Obviously you should replace the 'any's with your actual types!
add: (patern: object, cb: (msg: any, reply: any) => any) => object;
}