简体   繁体   中英

Is there a type for callback functions in TypeScript?

在此输入图像描述 The error says 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. But any is the same as no type, isn't there a suitable type for functions as parameters?

Instead of Function (or any ) you can use the following type for your callback parameter:

(ev: Event)=> any

This matches the type expected by addEventListener .

Here is the full function signature:

on(eventName: string, callback: (ev: Event)=> any, useCapture: boolean) : Dom.Element {
    //...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM