我有一个文件 .ts 并因以下代码收到此错误:
const hulk={
nombre:'Hulk',
smash(){
setTimeout(function(){
console.log(`${ this.nombre} smash!`); //HERE is the error but IDK why
},1000);
setTimeout(()=>{
console.log(`${ this.nombre} smash!`);
},1000);
}
}
hulk.smash();
我正在学习使用箭头函数以及使用箭头函数和使用函数的区别,但是当我在函数中输入“this”这个词时出现错误,因为当我在箭头函数中使用“this”时一切正常.
我试过添加
"noImplicitAny": false,
到
tsconfig.json
但这没有用。