简体   繁体   English

在最近的 eslint 中使用 Enums 时,如何避免阴影变量警告?

[英]How do I avoid shadowed variable warnings when using Enums in recent eslint?

Consider the following file:考虑以下文件:

export enum WorkshopOrderByType {
  featuredAt = "featuredAt",
  updatedAt = "updatedAt",
  createdAt = "createdAt",
  workshopStartDate = "workshopStartDate",
  attendingBatchStart = "attendingBatchStart",
}

The most recent eslint will complain that:最近的 eslint 会抱怨:

'WorkshopOrderByType' is already declared in the upper scope. 'WorkshopOrderByType' 已经在上层范围中声明。

This is described in the following eslint issue .这在以下 eslint 问题中有所描述。

The no-identifier-enum-member and prefer-literal-enum-member are apparently related to this, and there was talk of creating an exception for Enums as an option for no-shadow . no-identifier-enum-memberprefer-literal-enum-member显然与此相关,并且有人谈论为 Enums 创建一个例外作为no-shadow的选项。

But, as of now - how do I refactor the code above to fix the no-shadow warning?但是,截至目前 - 如何重构上面的代码以修复no-shadow警告?

The error comes from using the no-shadow rule instead of @typescript-eslint/no-shadow .错误来自使用no-shadow规则而不是@typescript-eslint/no-shadow

We added the:我们添加了:

"@typescript-eslint/no-shadow": "error",

And removed the corresponding并删除了相应的

"no-shadow": ...

rule which removed the warnings.删除警告的规则。

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

相关问题 使用 Typescript 时如何避免触发 eslint 的 for..in - How to avoid triggering eslint's for..in when using Typescript 使用`useFormikContent()`时如何防止`@typescript-eslint/unbound-method`错误? - How do I prevent a `@typescript-eslint/unbound-method` error when using `useFormikContent()`? 使用 Typescript 时如何避免 useEffect 中的无限循环? - How do I avoid an infinite loop in useEffect when using Typescript? 在 Visual Studio Code 中使用 TypeScript 时,如何将 TS 警告配置为显示为错误? - When using TypeScript in Visual Studio Code, how do I configure TS warnings to be shown as errors? 如何修复 linting 无阴影变量 wanring - how to fix a linting no shadowed variable wanring 使用笑话来测试数据是否与TypeScript类型相对应时避免警告 - Avoid warnings when using jest to test that data corresponds to TypeScript types 如何在 Typescript 中创建嵌套枚举 - How do I create nested enums in Typescript 如何禁用来自@typescript-eslint 的警告? - How to disable warnings from @typescript-eslint? 如何覆盖此ESLint TypeScript规则? - How do I override this ESLint TypeScript rule? 使用React + TypeScript,当使用启用了strictNullChecks的默认值的可选道具时,如何避免类型转换? - With React + TypeScript, how do I avoid typecasting when using optional props with defaults with strictNullChecks enabled?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM