TypeScript: Object is of type 'unknown'.

错误代码展示

TypeScript: Object is of type 'unknown'.

解决方案

e声明为any类型,如下所示:

TypeScript: Object is of type 'unknown'.

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