其他分享
首页 > 其他分享> > Typescript "this" 隐式具有类型 "any",因为它没有类型注释 'this' implicitly has type

Typescript "this" 隐式具有类型 "any",因为它没有类型注释 'this' implicitly has type

作者:互联网

问题:

"this" 隐式具有类型 "any",因为它没有类型注释
'this' implicitly has type 'any' because it does not have a type annotation

解决方案:

将this放在函数形参上声明即可,使用的时候this不会干扰形参传入顺序

const Demo: React.FC = () => {

    const fn = () => {
        return function (this: any, ...args: any[]) {
            let that = this
            console.log(args); // 还是1,2,3
            return that
        }
    }
    fn()(1, 2, 3)

    return (
        <div className="wrapper">
        </div>
    )
}

标签:because,return,隐式,Typescript,does,type,any
来源: https://www.cnblogs.com/ltfxy/p/16395205.html