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)

posted @   IslandZzzz  阅读(13001)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
点击右上角即可分享
微信分享提示