Skip to content
← Back to rules

typescript/no-unsafe-declaration-merging Correctness

This rule is turned on by default.

它的作用

禁止不安全的声明合并。

为什么这不好?

类和接口之间的声明合并是不安全的。 TypeScript 编译器不会检查属性是否已初始化,这可能导致 TypeScript 无法检测到会引发运行时错误的代码。

示例

以下是此规则的错误代码示例:

ts
interface Foo {}
class Foo {}

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

ts
interface Foo {}
class Bar {}

如何使用

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

json
{
  "rules": {
    "typescript/no-unsafe-declaration-merging": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "typescript/no-unsafe-declaration-merging": "error",
  },
});
bash
oxlint --deny typescript/no-unsafe-declaration-merging

版本

此规则于 v0.0.11 中添加。

参考资料