no-unnecessary-qualifier
Disallow unnecessary namespace qualifiers.
🛠
Some problems reported by this rule are automatically fixable by the --fix
ESLint command line option.
💭
This rule requires type information to run.
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": "warn"
}
};
Examples
- ❌ Incorrect
- ✅ Correct
enum A {
B,
C = A.B,
}
namespace A {
export type B = number;
const x: A.B = 3;
}
enum A {
B,
C = B,
}
namespace A {
export type B = number;
const x: B = 3;
}
Options
This rule is not configurable.
When Not To Use It
If you don't care about having unneeded enum or namespace qualifiers, then you don't need to use this rule.