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.
.eslintrc.cjs
module.exports = {
"rules": {
"@typescript-eslint/no-unnecessary-qualifier": "error"
}
};
示例
- ❌ 不正确
- ✅ 正确
enum A {
B,
C = A.B,
}
Open in Playgroundnamespace A {
export type B = number;
const x: A.B = 3;
}
Open in Playgroundenum A {
B,
C = B,
}
Open in Playgroundnamespace A {
export type B = number;
const x: B = 3;
}
Open in Playground何时不使用它
如果你明确更喜欢使用完全限定名称(例如出于明确性目的),则无需使用此规则。
英:If you explicitly prefer to use fully qualified names, such as for explicitness, then you don't need to use this rule.
选项
该规则不可配置。