TypeScript 此表达式不可调用。 类型 "Number" 没有调用签名。ts(2349) Snake.ts(64, 22): 是否缺少分号?
TS 报错:
此表达式不可调用。
类型 "String" 没有调用签名。ts(2349)Snake.ts(67, 63): 是否缺少分号?
let XX = (this.bodies[i-1] as HTMLElement).offsetLeft let YY = (this.bodies[i-1] as HTMLElement).offsetTop // 将值设置为当前身体上 (this.bodies[i] as HTMLElement).style.left = XX + 'px' (this.bodies[i] as HTMLElement).style.top = YY + 'px'
解决方案:
在每一个后面加上 ;
let XX = (this.bodies[i-1] as HTMLElement).offsetLeft; let YY = (this.bodies[i-1] as HTMLElement).offsetTop; // 将值设置为当前身体上 (this.bodies[i] as HTMLElement).style.left = XX + 'px'; (this.bodies[i] as HTMLElement).style.top = YY + 'px';