简体   繁体   English

掉毛时的阴影变量

[英]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.

相关问题 如何将 Angular 项目设置为在 linting 时始终发出错误而不是警告? - How do I set an Angular project to always emit errors instead of warnings when linting? 单击时如何删除按钮的框阴影? - How to remove the box shadow of the button when clicked? 在 shadow-root 中插入组件时不应用角度样式 - Angular styles not applying when insert component inside shadow-root 在 HighChart 中使用 getSVG() 打印 pdf 时如何去除文本阴影 - How to remove text shadow when print pdf using getSVG() in HighChart 在Angular 2中使用shadow DOM时,Node.contains()是否有效? - Does Node.contains() work when working with shadow DOM in Angular 2? 如果有掉毛问题,是否可以打破服务版本? - Is it possible to break ng serve build if there are linting issues? Linting 不适用于 tslint Angular 9 中的 Typescript 3.7 - Linting not working for Typescript 3.7 in tslint Angular 9 VS 代码 angular 和 typescript 在 templateUrl 上掉毛 - VS Code angular and typescript linting on templateUrl 使用NG2 Native View Encapsulation时,如何访问shadow-dom内的ElementRef - How do I access the ElementRef inside shadow-dom when using NG2 Native View Encapsulation 如何在没有 linting 错误的情况下配置角度项目 tsconfig paths[]? - how to configure an angular project tsconfig paths[] without linting errors?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM