Skip to main content

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": "error"
}
};

Try this rule in the playground ↗

Examples

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

Options

This rule is not configurable.

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 Performance Troubleshooting if you experience performance degredations after enabling type checked rules.

Resources