Skip to content
← Back to rules

typescript/no-unsafe-declaration-merging 正确性

This rule is turned on by default.

它做了什么

禁止不安全的声明合并。

为什么这是个问题?

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

示例

此规则的错误代码示例:

ts
interface Foo {}
class Foo {}

此规则的正确代码示例:

ts
interface Foo {}
class Bar {}

如何使用

通过配置文件或 CLI 启用此规则,可以使用:

json
{
  "rules": {
    "typescript/no-unsafe-declaration-merging": "error"
  }
}
bash
oxlint --deny typescript/no-unsafe-declaration-merging

参考资料