[英]Shadow variable when linting
When linting the following code: 整理以下代码时:
public doStuf = (): Promise<null> => {
const data = new Stuff(this.value);
if (this.state === 'test') {
data.mail = {
object: label,
files: this.dropppedFiles || []
};
return this.validate = (data) => null;
} else {
return this.validate = (data) => null;
}
}
I'm passing doStuff()
as promise to a child component that's why I need to keep the context with this.validate = (data) => null;
我将doStuff()
作为承诺传递给子组件,这就是为什么我需要使用this.validate = (data) => null;
保留上下文this.validate = (data) => null;
(There's maybe a more elegant way of doing things?) (也许有一种更优雅的做事方式?)
I get 我懂了
Shadowed variable: 'data' 阴影变量:“数据”
I tried unsing let
instead of const
but lint complains again about data is never modified, use const instead
我试图unsing let
,而不是const
,但皮棉再次抱怨data is never modified, use const instead
All my tests pass, and the component works as expected. 我所有的测试都通过了,该组件按预期工作。 How do I get rid of this error? 我如何摆脱这个错误?
EDIT: What works is this.validate = (boo = data) => null;
编辑:有效的方法是this.validate = (boo = data) => null;
How horrible is that? 那有多可怕?
EDIT: 编辑:
I actually want to pass parameters to the validate function and keep the arrow function structure at the same time. 我实际上想将参数传递给validate函数,并同时保留arrow函数的结构。 Something like: 就像是:
this.validate(data) = () => null;
When you write 当你写
this.validate = (data) => null;
this.validate
is a function with one parameter, data
, which means you can no longer reference the original data
variable. this.validate
是具有一个参数data
的函数,这意味着您不再可以引用原始data
变量。
If you call this parameter something else it will run fine. 如果您调用此参数,则可以正常运行。
this.validate = (param) => null;
EDIT 编辑
From your comment it sounds like you don't want to define but call the this.validate
function. 从您的评论看来,您不想定义,而是调用this.validate
函数。 In which case just do 在这种情况下
this.validate(data);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.