typescript/no-empty-interface Style
它的作用
禁止声明空接口。
为什么这不好?
TypeScript 中的空接口几乎没有任何作用:任何非空值都可以赋值给 {}。 使用空接口通常意味着程序员出错,例如误解了 {} 的概念,或者忘记填充字段。 该规则旨在确保代码中只声明有意义的接口。
示例
以下是此规则的错误代码示例:
ts
interface Foo {}
interface Bar extends Foo {}以下是此规则的正确代码示例:
ts
interface Foo {
member: string;
}
interface Bar extends Foo {
member: string;
}配置
该规则接受一个包含以下属性的配置对象:
allowSingleExtends
type: boolean
default: false
当设为 true 时,允许扩展单个接口的空接口。
如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"rules": {
"typescript/no-empty-interface": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
rules: {
"typescript/no-empty-interface": "error",
},
});bash
oxlint --deny typescript/no-empty-interface版本
此规则于 v0.0.6 中添加。
