2017-07-27 113 views
0

我有這樣的功能:Typescript如何定義回調函數?

.add({a: 1, b: 2}, function (msg, reply) { 
    reply({z: msg.z}) 
    }) 

它試圖這樣的事情:

interface SenecaMethods { 
    add: (patern: object, HERE SHOULD BE CALLBACK) => object; 
} 

如何爲這個定義類型?

回答

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; 
} 
+0

'reply'參數也是一個函數 –

相關問題