[英]Is there a type for callback functions in TypeScript?
The error says
Supplied parameter do not match any signature of call target
. 错误说
Supplied parameter do not match any signature of call target
。 When I replace Function
with any
as the second parameter's type, the error disappears. 当我将
Function
替换为any
作为第二个参数的类型时,错误消失。 But any
is the same as no type, isn't there a suitable type for functions as parameters? 但是
any
类型都没有类型,作为参数的功能是不是合适的类型?
Instead of Function
(or any
) you can use the following type for your callback
parameter: 您可以使用以下类型作为
callback
参数而不是Function
(或any
):
(ev: Event)=> any
This matches the type expected by addEventListener
. 这与
addEventListener
期望的类型匹配。
Here is the full function signature: 这是完整的功能签名:
on(eventName: string, callback: (ev: Event)=> any, useCapture: boolean) : Dom.Element {
//...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.