[英]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
警告我:
Unsafe member access.Login on an any value. eslint@typescript-eslint/no-unsafe-member-access
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.