TypeScript "this" 隐式具有类型 "any",因为它没有类型注释 'this' implicitly has type 'any' because it does not have a type annotation
问题:
"this" 隐式具有类型 "any",因为它没有类型注释
'this' implicitly has type 'any' because it does not have a type annotation
解决方案:
将this放在函数参数列表上声明类型即可,使用的时候this不会干扰形参传入顺序
const fn = () => {
return function (this: any, ...args: any[]) {
let that = this
console.log(args); // 1,2,3
return that
}
}
fn()(1, 2, 3)