Skip to content
← Back to rules

typescript/no-unnecessary-qualifier Style

💭 This rule requires type information.

它的作用

当引用的名称已经在作用域内时,禁止使用命名空间限定符。

为什么这很糟糕?

多余的限定符会增加噪音,并使类型引用更难阅读。

示例

以下是此规则的不正确代码示例:

ts
namespace A {
  export type B = number;
  const value: A.B = 1;
}

以下是此规则的正确代码示例:

ts
namespace A {
  export type B = number;
  const value: B = 1;
}

如何使用

To enable this rule using the config file or in the CLI, you can use:

json
{
  "options": {
    "typeAware": true
  },
  "rules": {
    "typescript/no-unnecessary-qualifier": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  options: { typeAware: true },
  rules: {
    "typescript/no-unnecessary-qualifier": "error",
  },
});
bash
oxlint --type-aware --deny typescript/no-unnecessary-qualifier

版本

该规则于 v1.49.0 中添加。

参考资料