为命名函数定义接口后,ts不再看到实际的函数吗?
interface InitiatePlayers {
(this: App, arg0: { amount: string }): void;
}
<InitiatePlayers>function initiatePlayers({ amount }) {
const PlayerWidth = this.width / 45;
this.nodes.push(
PlayerFactory({ width: PlayerWidth }),
PlayerFactory({ width: PlayerWidth, id: 'player-2', x: this.width - PlayerWidth })
);
};
app.onInit = function () {
// Add Players to the board
initiatePlayers.call(this, { amount: 2 }); // cannot find name of function
};
发布于 2020-12-04 22:36:56
看起来像是<InitiatePlayers>
语法把它搞乱了。
following code会正确检测函数的类型:
const app:any = {};
interface InitiatePlayers {
(this: any, arg0: { amount: string }): void;
}
const initiatePlayers: InitiatePlayers = function ({
amount,
}) {
};
app.onInit = function () {
initiatePlayers.call(this, { amount: 2 });
}
https://stackoverflow.com/questions/65145312
复制相似问题