简体   繁体   English

如何使用带有“this”的箭头 function 修复此 @typescript-eslint 警告?

[英]How can I fix this @typescript-eslint warning using an arrow function with “this” inside?

I'm using this typescript code:我正在使用这个 typescript 代码:

const tryThis = () => {
  const methods = {
    Login() {
      console.log("I'm Login()")
    },

    OnInit() {
      this.Login()
    }
  }

  return methods
}

but @typescript-eslint warns me with:@typescript-eslint警告我:

  1. Unsafe member access.Login on an any value. eslint@typescript-eslint/no-unsafe-member-access

  2. Unsafe call of an any typed value. eslint@typescript-eslint/no-unsafe-call

Why?为什么?

How can I fix this?我怎样才能解决这个问题?

Depending on your eslint config, the linter might not allow access to members with any type.根据您的 eslint 配置,linter 可能不允许访问any类型的成员。 To fix that you can fix that in your.eslintrc.js file with "no-unsafe-any": false check here , or type your function.要解决这个问题,您可以在 your.eslintrc.js 文件中使用"no-unsafe-any": false检查此处,或输入您的 function。

type ThisType = () => {
    Login(): void;
    OnInit(): void;
}

const tryThis:ThisType = () => {
  const methods = {
    Login() {
      console.log("I'm Login()")
    },

    OnInit() {
      this.Login()
    }
  }

  return methods
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修复@typescript-eslint/no-misused-promises 错误 - How to fix @typescript-eslint/no-misused-promises error 如何使用typescript-eslint验证typescript文件的ejs模板 - How can I validate an ejs template of a typescript file with typescript-eslint 如何将 typescript-eslint 规则添加到 eslint - How to add typescript-eslint rules to eslint 如何使用反应开发服务器禁用 @typescript-eslint/no-unused-vars 规则 - How can I disable @typescript-eslint/no-unused-vars rule with react dev server 使用`useFormikContent()`时如何防止`@typescript-eslint/unbound-method`错误? - How do I prevent a `@typescript-eslint/unbound-method` error when using `useFormikContent()`? 如何修复“未找到规则‘@typescript-eslint/no-use-before-declare’的定义。eslint(@typescript-eslint/no-use-before-declare)” - How to fix 'Definition for rule '@typescript-eslint/no-use-before-declare' was not found.eslint(@typescript-eslint/no-use-before-declare)' 如何配置@typescript-eslint 规则 - How to configure @typescript-eslint rules 如何禁用来自@typescript-eslint 的警告? - How to disable warnings from @typescript-eslint? 如何禁用@typescript-eslint/semi? - how disable @typescript-eslint/semi? 如何绕过警告 Unexpected any. 指定不同的类型 @typescript-eslint/no-explicit-any - How to bypass warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM