相关疑难解决方法(0)

TypeScript 可选回调参数与传递给它的匿名函数不匹配

我的 TS 回调有一个简单的问题。

我有这样的功能

...
//inside a class
    //function is supposed to optionally accept any callback function
    refreshConnection(callback?:Function) {
        //do something
        //then call the passed callback with no params
        callback();
    }

...

//in another component, i call this function like so
this.myclass.refreshConnection( () => {
    window.location.reload();
});

//but i get an error saying that the function parameter does not match a signature.

// i also tried callback?: (...args: any[]) => any but nothing.


ERROR in ./src/app/fb_connect.component.ts
Module build failed: Error: …
Run Code Online (Sandbox Code Playgroud)

javascript callback signature typescript

2
推荐指数
1
解决办法
4787
查看次数

标签 统计

callback ×1

javascript ×1

signature ×1

typescript ×1