TypeScript: Object is of type 'unknown'.
错误代码展示

解决方案
将e声明为any类型,如下所示:

// 修改蛇的X和Y值
try {
this.snake.X = X;
this.snake.Y = Y;
}catch(e:any){
// 进入到catch,说明出现了异常,游戏结束,弹出一个提示信息
alert(e.message);
// 将isLive设置为false
this.isLive = false;
}
学以致用,知行合一

浙公网安备 33010602011771号