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

2025-01-01 20:14:12

一. 问题

"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[]) {
    return this;
  };
};

目录

相关推荐
关于调用微软Bing API推送链接时,报:errorcode 3 message ERROR!!! InvalidApiKey如何调用百度和微软必应链接收录APIMac安装nvm时,各种问题总结react-app-rewired中如何设置ant-design主题,以及不生效问题Variable @primary-color-hover is undefinedAnt-Design-Vue Form 中,对于多选下拉表表单时,重置时,表单未正确展示