typescript 报错 Missing return type on function 编译不下去
class Snake {
//表示蛇得元素
head: HTMLElement;
bodies: HTMLCollection; //蛇身体包括蛇头
//获取蛇得容器
element: HTMLElement;
constructor() {
this.element = document.getElementById("snikeAnimal");
this.head = document.querySelector("#snikeAnimal > div") as HTMLElement;
this.bodies = this.element.getElementsByTagName("div");
}
//获取蛇得坐标(蛇头)
get X() {
return this.head.offsetLeft;
}
get Y() {
return this.head.offsetTop;
}
//设置蛇头得坐标
***set X(value: number) {
// console.log(this.head.style.left)
this.head.style.left = value + "px";
}
set Y(value: number) {
this.head.style.top = value + "px";
} ***
//蛇增加身体得方法
addBody() {
//向element 中添加一个div
this.element.insertAdjacentHTML("beforebegin", "<div></div>");
}
}```
## set X set Y 编译出差
在 .eslintrc.js文件中 rules添加 "@typescript-eslint/explicit-module-boundary-types": "off", // ts每个函数都要显式声明返回值