Skip to main content

no-unnecessary-qualifier

Disallow unnecessary namespace qualifiers.

🔧

此规则报告的一些问题可通过 --fix ESLint 命令行选项自动修复

💭

该规则需要 类型信息 才能运行,但这会带来性能方面的权衡。

TypeScript 枚举和命名空间的成员通常作为限定属性查找来检索:例如 Enum.member。但是,当在其父枚举或命名空间内访问时,不需要限定符:例如,仅 member 而不是 Enum.member。此规则报告何时不需要枚举或命名空间限定符。

¥Members of TypeScript enums and namespaces are generally retrieved as qualified property lookups: e.g. Enum.member. However, when accessed within their parent enum or namespace, the qualifier is unnecessary: e.g. just member instead of Enum.member. This rule reports when an enum or namespace qualifier is unnecessary.

eslint.config.mjs
export default tseslint.config({
rules: {
"@typescript-eslint/no-unnecessary-qualifier": "error"
}
});

在线运行试试这个规则 ↗

示例

¥Examples

enum A {
B,
C = A.B,
}
Open in Playground
namespace A {
export type B = number;
const x: A.B = 3;
}
Open in Playground

选项

该规则不可配置。

何时不使用它

¥When Not To Use It

如果你明确更喜欢使用完全限定名称(例如出于明确性目的),则无需使用此规则。

¥If you explicitly prefer to use fully qualified names, such as for explicitness, then you don't need to use this rule.


Type checked lint rules are more powerful than traditional lint rules, but also require configuring type checked linting.

See Troubleshooting > Linting with Type Information > Performance if you experience performance degradations after enabling type checked rules.

'## 资源'